Skip to content

Commit

Permalink
Add --yes flag to egress-ip commands (#4033)
Browse files Browse the repository at this point in the history
Signed-off-by: Akshit Garg <[email protected]>
  • Loading branch information
gargakshit authored Oct 24, 2024
1 parent d123a9c commit 68106da
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion internal/command/machine/egress_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func newAllocateEgressIp() *cobra.Command {
flag.Add(cmd,
flag.App(),
flag.AppConfig(),
flag.Yes(),
)

cmd.Args = cobra.ExactArgs(1)
Expand Down Expand Up @@ -93,6 +94,7 @@ func newReleaseEgressIP() *cobra.Command {
flag.Add(cmd,
flag.App(),
flag.AppConfig(),
flag.Yes(),
)

cmd.Args = cobra.ExactArgs(1)
Expand All @@ -108,7 +110,7 @@ func runAllocateEgressIP(ctx context.Context) (err error) {
machineId = args[0]
)

if !flag.GetBool(ctx, "yes") {
if !flag.GetYes(ctx) {
msg := `Looks like you're allocating a static egress (outgoing) IP. This is an advanced feature, and is not needed by most apps.
Are you sure this is what you want?`

Expand Down Expand Up @@ -167,6 +169,21 @@ func runReleaseEgressIP(ctx context.Context) (err error) {
machineId = args[0]
)

if !flag.GetYes(ctx) {
msg := `Are you sure?`

switch confirmed, err := prompt.Confirm(ctx, msg); {
case err == nil:
if !confirmed {
return nil
}
case prompt.IsNonInteractive(err):
return prompt.NonInteractiveError("yes flag must be specified when not running interactively")
default:
return err
}
}

v4, v6, err := client.ReleaseEgressIPAddress(ctx, appName, machineId)
if err != nil {
return err
Expand Down

0 comments on commit 68106da

Please sign in to comment.