From 30421fd5cf962c3c67221f4efaf2896458f3736b Mon Sep 17 00:00:00 2001 From: joohwan Date: Thu, 17 Sep 2026 10:53:27 +0800 Subject: [PATCH 1/2] feat: support flag autoPause & autoResume --- README.md | 6 ++++++ cmd/sandbox/create.go | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/README.md b/README.md index ea0854c..8053fc4 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,12 @@ ucloud-sandbox-cli sandbox create base \ --mount :/cache ``` +开启自动暂停/自动恢复后,沙箱在超时被暂停后,下次访问时会自动恢复运行: + +```bash +ucloud-sandbox-cli sandbox create base --auto-pause --auto-resume --detach +``` + > 创建成功后,CLI 会自动连接终端,您可以像操作本地 Shell 一样执行命令。按`Ctrl+D`或输入`exit`退出连接(沙箱继续运行)。 ### 连接现有沙箱 diff --git a/cmd/sandbox/create.go b/cmd/sandbox/create.go index f621bd1..44cd7e7 100644 --- a/cmd/sandbox/create.go +++ b/cmd/sandbox/create.go @@ -13,6 +13,8 @@ import ( func newCreateCmd() *cobra.Command { var timeout int var detach bool + var autoPause bool + var autoResume bool var mountSpecs []string cmd := &cobra.Command{ @@ -40,6 +42,12 @@ func newCreateCmd() *cobra.Command { if timeout > 0 { opts = append(opts, sdk.WithTimeout(timeout)) } + if autoPause { + opts = append(opts, sdk.WithAutoPause(true)) + } + if autoResume { + opts = append(opts, sdk.WithAutoResume(sdk.AutoResumePolicyOn)) + } if len(mountSpecs) > 0 { mounts, err := parseVolumeMounts(mountSpecs) if err != nil { @@ -64,6 +72,8 @@ func newCreateCmd() *cobra.Command { cmd.Flags().IntVar(&timeout, "timeout", 0, "Sandbox timeout in seconds") cmd.Flags().BoolVar(&detach, "detach", false, "Do not connect to the sandbox after creation") + cmd.Flags().BoolVar(&autoPause, "auto-pause", false, "Automatically pause the sandbox when the timeout is reached") + cmd.Flags().BoolVar(&autoResume, "auto-resume", false, "Automatically resume the sandbox when it is paused") cmd.Flags().StringArrayVar(&mountSpecs, "mount", nil, "Mount volume as : (repeatable)") return cmd } From 662b2687fe4ae7fff1281454b92b7be3c40c7838 Mon Sep 17 00:00:00 2001 From: joohwan Date: Fri, 18 Sep 2026 16:10:33 +0800 Subject: [PATCH 2/2] feat: support flag snapshot name --- cmd/snapshot/create.go | 18 ++++++++++++++++-- go.mod | 2 +- go.sum | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cmd/snapshot/create.go b/cmd/snapshot/create.go index 9b9facd..1fa0bc0 100644 --- a/cmd/snapshot/create.go +++ b/cmd/snapshot/create.go @@ -6,9 +6,12 @@ import ( "github.com/spf13/cobra" "github.com/ucloud/ucloud-sandbox-cli/internal/config" + sdk "github.com/ucloud/ucloud-sandbox-sdk-go" ) func newCreateCmd() *cobra.Command { + var name string + cmd := &cobra.Command{ Use: "create ", Aliases: []string{"cr"}, @@ -34,16 +37,27 @@ func newCreateCmd() *cobra.Command { return fmt.Errorf("failed to connect to sandbox %s: %w", sandboxID, err) } + var opts []sdk.SnapshotOption + if name != "" { + opts = append(opts, sdk.WithSnapshotName(name)) + } + // Create snapshot from the sandbox - snapshot, err := sbx.CreateSnapshot(ctx) + snapshot, err := sbx.CreateSnapshot(ctx, opts...) if err != nil { return fmt.Errorf("failed to create snapshot: %w", err) } - fmt.Printf("Snapshot created: %s\n", snapshot.SnapshotID) + if name != "" { + fmt.Printf("Snapshot created: %s (%s)\n", snapshot.SnapshotID, name) + } else { + fmt.Printf("Snapshot created: %s\n", snapshot.SnapshotID) + } return nil }, } + cmd.Flags().StringVarP(&name, "name", "n", "", "Snapshot name") + return cmd } diff --git a/go.mod b/go.mod index b60d401..d0ea507 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/schollz/progressbar/v3 v3.19.1 github.com/spf13/cobra v1.10.2 github.com/stretchr/testify v1.11.1 - github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260910030832-8ef53e9144e2 + github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260918080929-c96bfe4b7c62 golang.org/x/mod v0.40.0 golang.org/x/term v0.44.0 ) diff --git a/go.sum b/go.sum index 69aa25b..0c3dab9 100644 --- a/go.sum +++ b/go.sum @@ -52,6 +52,8 @@ github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260901104032-07e3348267f2 h1:hW github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260901104032-07e3348267f2/go.mod h1:YrCrvJEqOBr33ToGyKcFB+ZcTY0EkueE4H0uyqNdsb8= github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260910030832-8ef53e9144e2 h1:m9JyzdCMKqQh05bphya4OZLZUb1DIsWDmmqlZeFRtyg= github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260910030832-8ef53e9144e2/go.mod h1:YrCrvJEqOBr33ToGyKcFB+ZcTY0EkueE4H0uyqNdsb8= +github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260918080929-c96bfe4b7c62 h1:Bd6kEbBmOoF5qP1kaKjnKnWMhGKvlmOtBn1Co/xY9N4= +github.com/ucloud/ucloud-sandbox-sdk-go v0.0.0-20260918080929-c96bfe4b7c62/go.mod h1:YrCrvJEqOBr33ToGyKcFB+ZcTY0EkueE4H0uyqNdsb8= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=