Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 6a8fbea

Browse files
committed
Add confirmation dialog to 'coder envs edit'
1 parent 2aeb038 commit 6a8fbea

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

internal/cmd/envs.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ func editEnvCmd() *cobra.Command {
430430
gpus int
431431
follow bool
432432
user string
433+
force bool
433434
)
434435

435436
cmd := &cobra.Command{
@@ -482,6 +483,19 @@ coder envs edit back-end-env --disk 20`,
482483
return err
483484
}
484485

486+
if !force && env.LatestStat.ContainerStatus == coder.EnvironmentOn {
487+
_, err = (&promptui.Prompt{
488+
Label: fmt.Sprintf("Rebuild environment \"%s\"? (will destroy any work outside of /home)", env.Name),
489+
IsConfirm: true,
490+
}).Run()
491+
if err != nil {
492+
return clog.Fatal(
493+
"failed to confirm prompt", clog.BlankLine,
494+
clog.Tipf(`use "--force" to rebuild without a confirmation prompt`),
495+
)
496+
}
497+
}
498+
485499
if err := client.EditEnvironment(ctx, env.ID, *req); err != nil {
486500
return xerrors.Errorf("failed to apply changes to environment %q: %w", envName, err)
487501
}
@@ -510,6 +524,7 @@ coder envs edit back-end-env --disk 20`,
510524
cmd.Flags().IntVarP(&gpus, "gpu", "g", 0, "The amount of disk storage to provision the environment with.")
511525
cmd.Flags().BoolVar(&follow, "follow", false, "follow buildlog after initiating rebuild")
512526
cmd.Flags().StringVar(&user, "user", coder.Me, "Specify the user whose resources to target")
527+
cmd.Flags().BoolVar(&force, "force", false, "force rebuild without showing a confirmation prompt")
513528
return cmd
514529
}
515530

0 commit comments

Comments
 (0)