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

feat: Prompt user to rebuild workspace on coder sh #223

Merged
merged 1 commit into from
Jan 22, 2021

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Jan 21, 2021

Quality of Life Feature

When a user does coder sh <env>, the cli first checks if that environment is OFF or if it requires a rebuild before using. It will then prompt the user if they want to rebuild the workspace.

To test

Off

coder env stop <workspace>
coder sh <workspace>

Rebuild Message

If the environment has a required rebuild message, the output looks like this:
Screenshot from 2021-01-21 16-22-16

Questions:

Currently --force does not work for this feature, and there is no --no-rebuild flag. The current command has flag parsing disabled. Are these kinds of flags required? I imagine a user prompt would make scripting coder sh rather annoying.

@Emyrk Emyrk requested a review from cmoog January 21, 2021 23:00
Comment on lines 135 to 139
confirm := promptui.Prompt{
Label: rebuildReason + " Do you wish to rebuild it now? (this will take a moment)",
IsConfirm: true,
}
if _, err := confirm.Run(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should only prompt the user if they are in an interactive terminal

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this what you had in mind to check for that?
https://github.com/cdr/coder-cli/blob/423279755e6607dc1236066d47fd5333d25268b5/internal/cmd/shell.go#L107-L109

So these will not prompt:

$GOPATH/bin/coder sh tiny | echo
`/home/coder/go/bin/coder sh tiny`

Is there a specific way of executing you had in mind? I took this code from the runCommand, an alternative is I could use https://rosettacode.org/wiki/Check_output_device_is_a_terminal#Go. I think they do the same thing, so I kept it consistent with the other way we did it.

Copy link
Contributor

@cmoog cmoog Jan 22, 2021

Choose a reason for hiding this comment

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

Yeah that's what I had in mind. That said, point taken... this is certainly leaky behavior. Since this is more of a nicety, and we can assume 90% of cases will be coder sh [env] without pipes or args... I think we should do the cautious thing and only show the prompt when we know for certain the output is interactive.

Regarding coder sh tiny | echo, erroring out as we do now with the helpful error message seems sufficient.

Copy link
Member Author

Choose a reason for hiding this comment

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

I left a comment that --force or --no-prompt would be a clear way for someone to determine behavior, but adding flags to this command is non-trivial because the flag parsing is disabled

Copy link
Member Author

Choose a reason for hiding this comment

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

I am assuming running this via cron and other ways won't trigger the prompt too. So I can see how this is helpful, but I don't think it's obvious if I was just writing some bash scripts. Bash scripts will still trigger the prompt if you just run them ./script.sh.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, agreed. Doesn't appear to be an easy win here.

@Emyrk Emyrk marked this pull request as ready for review January 22, 2021 15:17
@Emyrk
Copy link
Member Author

Emyrk commented Jan 22, 2021

@cmoog addressed all comments, the last sticky point is if the current interactive shell behavior is sufficient

Comment on lines 135 to 139
confirm := promptui.Prompt{
Label: rebuildReason + " Do you wish to rebuild it now? (this will take a moment)",
IsConfirm: true,
}
if _, err := confirm.Run(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, agreed. Doesn't appear to be an easy win here.

Copy link
Contributor

@cmoog cmoog left a comment

Choose a reason for hiding this comment

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

Looks good. Nice work.

I think the interactive behavior, as you have it, is the best we're going to get for now.

If the workspace is OFF or a rebuild is required, prompt
the user to rebuild right away. This prompt only occurs
in an interactive shell
@Emyrk Emyrk force-pushed the stevenmasley/ch6142_sh_start_wksp branch from 6752124 to 7a4f2db Compare January 22, 2021 17:57
@Emyrk Emyrk merged commit 288197a into master Jan 22, 2021
@Emyrk Emyrk deleted the stevenmasley/ch6142_sh_start_wksp branch January 22, 2021 18:36
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.

2 participants