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

Conversation

lilshoff
Copy link
Contributor

@lilshoff lilshoff requested review from jawnsy and fuskovic March 30, 2021 17:55
@lilshoff lilshoff self-assigned this Mar 30, 2021
Copy link
Contributor

@jawnsy jawnsy left a comment

Choose a reason for hiding this comment

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

LGTM! 🔥

@@ -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 👍

@@ -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),
Copy link
Contributor

Choose a reason for hiding this comment

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

it doesn't matter for anything, but fyi you can use %q to double quote your string (you can tell that I am extremely lazy)

Suggested change
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 /home)", env.Name),

You might also want to mention "your home directory" instead of a specific path, because as a special case, root's home directory is /root

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree on "your home directory"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh nice - didn't know about that %q 🤯 🙌

And yeah the rename from /home to your home directory is a good call. Fixed it on the rebuild prompt too 👌

@@ -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 ❤️

@lilshoff lilshoff merged commit c4d9c0e into master Mar 30, 2021
@lilshoff lilshoff deleted the lilshoff/confirm-edit-env branch March 30, 2021 18:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants