From 6a8fbea56bde5b5ed629c18921e68ad3eb1d7f50 Mon Sep 17 00:00:00 2001 From: Lily Hoffman <0xlilyhoffman@gmail.com> Date: Tue, 30 Mar 2021 17:28:09 +0000 Subject: [PATCH 1/5] Add confirmation dialog to 'coder envs edit' --- internal/cmd/envs.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/internal/cmd/envs.go b/internal/cmd/envs.go index ab0b6e47..7bc087d9 100644 --- a/internal/cmd/envs.go +++ b/internal/cmd/envs.go @@ -430,6 +430,7 @@ func editEnvCmd() *cobra.Command { gpus int follow bool user string + force bool ) cmd := &cobra.Command{ @@ -482,6 +483,19 @@ coder envs edit back-end-env --disk 20`, return err } + if !force && env.LatestStat.ContainerStatus == coder.EnvironmentOn { + _, err = (&promptui.Prompt{ + Label: fmt.Sprintf("Rebuild environment \"%s\"? (will destroy any work outside of /home)", env.Name), + IsConfirm: true, + }).Run() + if err != nil { + return clog.Fatal( + "failed to confirm prompt", clog.BlankLine, + clog.Tipf(`use "--force" to rebuild without a confirmation prompt`), + ) + } + } + if err := client.EditEnvironment(ctx, env.ID, *req); err != nil { return xerrors.Errorf("failed to apply changes to environment %q: %w", envName, err) } @@ -510,6 +524,7 @@ coder envs edit back-end-env --disk 20`, cmd.Flags().IntVarP(&gpus, "gpu", "g", 0, "The amount of disk storage to provision the environment with.") cmd.Flags().BoolVar(&follow, "follow", false, "follow buildlog after initiating rebuild") cmd.Flags().StringVar(&user, "user", coder.Me, "Specify the user whose resources to target") + cmd.Flags().BoolVar(&force, "force", false, "force rebuild without showing a confirmation prompt") return cmd } From 4175b362d4f8816b95f128fcf3d423a113d0410c Mon Sep 17 00:00:00 2001 From: Lily Hoffman <0xlilyhoffman@gmail.com> Date: Tue, 30 Mar 2021 17:37:32 +0000 Subject: [PATCH 2/5] Update docs for coder envs edit --- docs/coder_envs_edit.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/coder_envs_edit.md b/docs/coder_envs_edit.md index faf298d8..a8cc2551 100644 --- a/docs/coder_envs_edit.md +++ b/docs/coder_envs_edit.md @@ -24,6 +24,7 @@ coder envs edit back-end-env --disk 20 -c, --cpu float32 The number of cpu cores the environment should be provisioned with. -d, --disk int The amount of disk storage an environment should be provisioned with. --follow follow buildlog after initiating rebuild + --force force rebuild without showing a confirmation prompt -g, --gpu int The amount of disk storage to provision the environment with. -h, --help help for edit -i, --image string name of the image you want the environment to be based off of. From 6496d5a375a7cc5c7748b0c45ff3d9e80f465c38 Mon Sep 17 00:00:00 2001 From: Lily Hoffman <0xlilyhoffman@gmail.com> Date: Tue, 30 Mar 2021 17:42:55 +0000 Subject: [PATCH 3/5] Update tests --- internal/cmd/envs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cmd/envs_test.go b/internal/cmd/envs_test.go index e80a93a5..b28ea6c7 100644 --- a/internal/cmd/envs_test.go +++ b/internal/cmd/envs_test.go @@ -108,7 +108,7 @@ func Test_env_create(t *testing.T) { // edit the CPU of the environment cpu = 2.1 - res = execute(t, nil, "envs", "edit", name, fmt.Sprintf("--cpu=%f", cpu), "--follow") + res = execute(t, nil, "envs", "edit", name, fmt.Sprintf("--cpu=%f", cpu), "--follow", "--force") res.success(t) // assert that the CPU actually did change after edit From 58154afc8bc49f9635e31bf64fb908382e917c62 Mon Sep 17 00:00:00 2001 From: Lily Hoffman <0xlilyhoffman@gmail.com> Date: Tue, 30 Mar 2021 18:02:45 +0000 Subject: [PATCH 4/5] Fix confirmation prompt ('/home' -> 'your home directory') --- internal/cmd/envs.go | 2 +- internal/cmd/rebuild.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cmd/envs.go b/internal/cmd/envs.go index 7bc087d9..78f827b2 100644 --- a/internal/cmd/envs.go +++ b/internal/cmd/envs.go @@ -485,7 +485,7 @@ coder envs edit back-end-env --disk 20`, if !force && env.LatestStat.ContainerStatus == coder.EnvironmentOn { _, err = (&promptui.Prompt{ - Label: fmt.Sprintf("Rebuild environment \"%s\"? (will destroy any work outside of /home)", env.Name), + Label: fmt.Sprintf("Rebuild environment \"%s\"? (will destroy any work outside of your home directory)", env.Name), IsConfirm: true, }).Run() if err != nil { diff --git a/internal/cmd/rebuild.go b/internal/cmd/rebuild.go index bf998b40..0403beb9 100644 --- a/internal/cmd/rebuild.go +++ b/internal/cmd/rebuild.go @@ -43,7 +43,7 @@ coder envs rebuild backend-env --force`, if !force && env.LatestStat.ContainerStatus == coder.EnvironmentOn { _, err = (&promptui.Prompt{ - Label: fmt.Sprintf("Rebuild environment \"%s\"? (will destroy any work outside of /home)", env.Name), + Label: fmt.Sprintf("Rebuild environment \"%s\"? (will destroy any work outside of your home directory)", env.Name), IsConfirm: true, }).Run() if err != nil { From a50b7ecbdd7c24e6a92a011828dc686eb8d8cd6f Mon Sep 17 00:00:00 2001 From: Lily Hoffman <0xlilyhoffman@gmail.com> Date: Tue, 30 Mar 2021 18:08:29 +0000 Subject: [PATCH 5/5] Use %q to quote strings --- internal/cmd/envs.go | 2 +- internal/cmd/rebuild.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cmd/envs.go b/internal/cmd/envs.go index 78f827b2..2ed190c0 100644 --- a/internal/cmd/envs.go +++ b/internal/cmd/envs.go @@ -485,7 +485,7 @@ coder envs edit back-end-env --disk 20`, if !force && env.LatestStat.ContainerStatus == coder.EnvironmentOn { _, err = (&promptui.Prompt{ - Label: fmt.Sprintf("Rebuild environment \"%s\"? (will destroy any work outside of your home directory)", env.Name), + Label: fmt.Sprintf("Rebuild environment %q? (will destroy any work outside of your home directory)", env.Name), IsConfirm: true, }).Run() if err != nil { diff --git a/internal/cmd/rebuild.go b/internal/cmd/rebuild.go index 0403beb9..8cd6ca2e 100644 --- a/internal/cmd/rebuild.go +++ b/internal/cmd/rebuild.go @@ -43,7 +43,7 @@ coder envs rebuild backend-env --force`, if !force && env.LatestStat.ContainerStatus == coder.EnvironmentOn { _, err = (&promptui.Prompt{ - Label: fmt.Sprintf("Rebuild environment \"%s\"? (will destroy any work outside of your home directory)", env.Name), + Label: fmt.Sprintf("Rebuild environment %q? (will destroy any work outside of your home directory)", env.Name), IsConfirm: true, }).Run() if err != nil {