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 c4d9c0e

Browse files
authored
Add confirmation prompt to 'coder envs edit' (#305)
1 parent 2aeb038 commit c4d9c0e

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

docs/coder_envs_edit.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ coder envs edit back-end-env --disk 20
2424
-c, --cpu float32 The number of cpu cores the environment should be provisioned with.
2525
-d, --disk int The amount of disk storage an environment should be provisioned with.
2626
--follow follow buildlog after initiating rebuild
27+
--force force rebuild without showing a confirmation prompt
2728
-g, --gpu int The amount of disk storage to provision the environment with.
2829
-h, --help help for edit
2930
-i, --image string name of the image you want the environment to be based off of.

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 %q? (will destroy any work outside of your home directory)", 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

internal/cmd/envs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func Test_env_create(t *testing.T) {
108108

109109
// edit the CPU of the environment
110110
cpu = 2.1
111-
res = execute(t, nil, "envs", "edit", name, fmt.Sprintf("--cpu=%f", cpu), "--follow")
111+
res = execute(t, nil, "envs", "edit", name, fmt.Sprintf("--cpu=%f", cpu), "--follow", "--force")
112112
res.success(t)
113113

114114
// assert that the CPU actually did change after edit

internal/cmd/rebuild.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ coder envs rebuild backend-env --force`,
4343

4444
if !force && env.LatestStat.ContainerStatus == coder.EnvironmentOn {
4545
_, err = (&promptui.Prompt{
46-
Label: fmt.Sprintf("Rebuild environment \"%s\"? (will destroy any work outside of /home)", env.Name),
46+
Label: fmt.Sprintf("Rebuild environment %q? (will destroy any work outside of your home directory)", env.Name),
4747
IsConfirm: true,
4848
}).Run()
4949
if err != nil {

0 commit comments

Comments
 (0)