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.

Add confirmation prompt to 'coder envs edit' #305

Merged
merged 5 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/coder_envs_edit.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions internal/cmd/envs.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ func editEnvCmd() *cobra.Command {
gpus int
follow bool
user string
force bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👍

)

cmd := &cobra.Command{
Expand Down Expand Up @@ -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 %q? (will destroy any work outside of your home directory)", 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)
}
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/envs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love that you added a test, TY ❤️

res.success(t)

// assert that the CPU actually did change after edit
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/rebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 %q? (will destroy any work outside of your home directory)", env.Name),
IsConfirm: true,
}).Run()
if err != nil {
Expand Down