Skip to content

Commit bc07847

Browse files
committed
feat: add -y|--yes flag for 'us deploy' to auto-confirm deployment plan
1 parent 8a273db commit bc07847

File tree

4 files changed

+46
-43
lines changed

4 files changed

+46
-43
lines changed

.mise.lock

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,28 @@
1-
[tools."aqua:vektra/mockery"]
1+
[[tools."aqua:vektra/mockery"]]
22
version = "3.5.3"
33
backend = "aqua:vektra/mockery"
44

5-
[tools."aqua:vektra/mockery".checksums]
6-
"mockery_3.5.3_Darwin_arm64.tar.gz" = "sha256:a3a94b14c7414e148f2252199ffc4a0108d311358f3d336cbe05bb73cb203704"
7-
"mockery_3.5.3_Linux_x86_64.tar.gz" = "sha256:ebce416b0175338525246c376885a1579ca6cd4d4015140ba0c70e6b5339a39c"
8-
9-
[tools.go]
10-
version = "1.23.10"
5+
[[tools.go]]
6+
version = "1.23.12"
117
backend = "core:go"
128

13-
[tools.go.checksums]
14-
"go1.23.10.darwin-arm64.tar.gz" = "sha256:25c64bfa8a8fd8e7f62fb54afa4354af8409a4bb2358c2699a1003b733e6fce5"
15-
"go1.23.10.linux-amd64.tar.gz" = "sha256:535f9f81802499f2a7dbfa70abb8fda3793725fcc29460f719815f6e10b5fd60"
9+
[tools.go.platforms.macos-arm64]
10+
checksum = "sha256:5bfa117e401ae64e7ffb960243c448b535fe007e682a13ff6c7371f4a6f0ccaa"
11+
size = 71669468
12+
url = "https://dl.google.com/go/go1.23.12.darwin-arm64.tar.gz"
1613

17-
[tools.golangci-lint]
14+
[[tools.golangci-lint]]
1815
version = "2.2.2"
1916
backend = "aqua:golangci/golangci-lint"
2017

21-
[tools.golangci-lint.checksums]
22-
"golangci-lint-2.2.2-darwin-arm64.tar.gz" = "sha256:d84d94d042c0d495fd1746f3d18948a75de163b17a14e8de3ef840928dd2df74"
23-
"golangci-lint-2.2.2-linux-amd64.tar.gz" = "sha256:c27fbde948a87d326feacd21df2f61a9c54dbd2e3bfa185c0a1cd6917a6f964f"
24-
25-
[tools.protoc]
18+
[[tools.protoc]]
2619
version = "27.3"
2720
backend = "aqua:protocolbuffers/protobuf/protoc"
2821

29-
[tools.protoc.checksums]
30-
"protoc-27.3-linux-x86_64.zip" = "sha256:6dab2adab83f915126cab53540d48957c40e9e9023969c3e84d44bfb936c7741"
31-
"protoc-27.3-osx-aarch_64.zip" = "sha256:b22116bd97cdbd7ea25346abe635a9df268515fe5ef5afa93cd9a68fc2513f84"
32-
33-
[tools.protoc-gen-go]
22+
[[tools.protoc-gen-go]]
3423
version = "1.34.2"
3524
backend = "aqua:protocolbuffers/protobuf-go/protoc-gen-go"
3625

37-
[tools.protoc-gen-go.checksums]
38-
"protoc-gen-go.v1.34.2.darwin.arm64.tar.gz" = "sha256:17aca7f948dbb624049030cf841e35895cf34183ba006e721247fdeb95ff2780"
39-
"protoc-gen-go.v1.34.2.linux.amd64.tar.gz" = "sha256:b87bc134dee55576a842141bf0ed27761c635d746780fce5dee038c6dd16554f"
40-
41-
[tools.protoc-gen-go-grpc]
26+
[[tools.protoc-gen-go-grpc]]
4227
version = "1.5.1"
4328
backend = "aqua:grpc/grpc-go/protoc-gen-go-grpc"
44-
45-
[tools.protoc-gen-go-grpc.checksums]
46-
"protoc-gen-go-grpc.v1.5.1.darwin.arm64.tar.gz" = "sha256:d6083feb51dcfe59f26793e99ef01ef5eac68b64294ec2546711f614ac5878f3"
47-
"protoc-gen-go-grpc.v1.5.1.linux.amd64.tar.gz" = "sha256:a6cac4ea731e54aea304ad44d704a69d1cdc82997084b33637e21a89dc9229d6"

cmd/uncloud/deploy.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type deployOptions struct {
2222
services []string
2323
noBuild bool
2424
recreate bool
25+
yes bool
2526

2627
context string
2728
}
@@ -43,16 +44,19 @@ func NewDeployCommand() *cobra.Command {
4344
},
4445
}
4546

46-
cmd.Flags().StringSliceVarP(&opts.files, "file", "f", nil,
47-
"One or more Compose files to deploy services from. (default compose.yaml)")
48-
cmd.Flags().StringSliceVarP(&opts.profiles, "profile", "p", nil,
49-
"One or more Compose profiles to enable.")
5047
cmd.Flags().StringVarP(&opts.context, "context", "c", "",
5148
"Name of the cluster context to deploy to (default is the current context)")
49+
cmd.Flags().StringSliceVarP(&opts.files, "file", "f", nil,
50+
"One or more Compose files to deploy services from. (default compose.yaml)")
5251
cmd.Flags().BoolVarP(&opts.noBuild, "no-build", "n", false,
5352
"Do not build images before deploying services. (default false)")
53+
cmd.Flags().StringSliceVarP(&opts.profiles, "profile", "p", nil,
54+
"One or more Compose profiles to enable.")
5455
cmd.Flags().BoolVar(&opts.recreate, "recreate", false,
5556
"Recreate containers even if their configuration and image haven't changed.")
57+
cmd.Flags().BoolVarP(&opts.yes, "yes", "y", false,
58+
"Auto-confirm deployment plan. Enabled by default when running non-interactively,\n"+
59+
"e.g., in CI/CD pipelines.")
5660

5761
// TODO: Consider adding a filter flag to specify which machines to deploy to but keep the rest running.
5862
// Could be useful to test a new version on a subset of machines before rolling out to all.
@@ -136,13 +140,21 @@ func runDeploy(ctx context.Context, uncli *cli.CLI, opts deployOptions) error {
136140
}
137141
fmt.Println()
138142

139-
confirmed, err := cli.Confirm()
140-
if err != nil {
141-
return fmt.Errorf("confirm deployment: %w", err)
142-
}
143-
if !confirmed {
144-
fmt.Println("Cancelled. No changes were made.")
145-
return nil
143+
// Ask for plan confirmation before proceeding with the deployment unless running in non-interactive mode
144+
// or --yes is specified.
145+
if !opts.yes {
146+
if cli.IsStdinTerminal() {
147+
confirmed, err := cli.Confirm()
148+
if err != nil {
149+
return fmt.Errorf("confirm deployment: %w", err)
150+
}
151+
if !confirmed {
152+
fmt.Println("Cancelled. No changes were made.")
153+
return nil
154+
}
155+
} else {
156+
fmt.Println("Auto-confirming deployment plan in non-interactive mode.")
157+
}
146158
}
147159

148160
return progress.RunWithTitle(ctx, func(ctx context.Context) error {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ require (
5252
golang.org/x/net v0.35.0
5353
golang.org/x/sync v0.11.0
5454
golang.org/x/sys v0.31.0
55+
golang.org/x/term v0.29.0
5556
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173
5657
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6
5758
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576
@@ -307,7 +308,6 @@ require (
307308
golang.org/x/crypto/x509roots/fallback v0.0.0-20240507223354-67b13616a595 // indirect
308309
golang.org/x/exp v0.0.0-20241215155358-4a5509556b9e // indirect
309310
golang.org/x/mod v0.23.0 // indirect
310-
golang.org/x/term v0.29.0 // indirect
311311
golang.org/x/text v0.22.0 // indirect
312312
golang.org/x/time v0.8.0 // indirect
313313
golang.org/x/tools v0.30.0 // indirect

internal/cli/prompt.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package cli
22

3-
import "github.com/charmbracelet/huh"
3+
import (
4+
"os"
5+
6+
"github.com/charmbracelet/huh"
7+
"golang.org/x/term"
8+
)
49

510
func Confirm() (bool, error) {
611
var confirmed bool
@@ -21,3 +26,8 @@ func Confirm() (bool, error) {
2126

2227
return confirmed, nil
2328
}
29+
30+
// IsStdinTerminal checks if the standard input is a terminal (TTY).
31+
func IsStdinTerminal() bool {
32+
return term.IsTerminal(int(os.Stdin.Fd()))
33+
}

0 commit comments

Comments
 (0)