Skip to content
Open
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
9 changes: 9 additions & 0 deletions internal/iostreams/prompts.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ func errInteractivityFlags(cfg PromptConfig, message string, options []string) e
}
}
remediation = fmt.Sprintf("Re-run with one of the `--%s` values shown above", flagName)
case len(flags) == 1 && isPasswordPrompt(cfg):
remediation = fmt.Sprintf("Run this command in an interactive terminal to enter the value with hidden input\nThe `--%s` flag also works, but can leave the value in shell history", flags[0].Name)
case len(flags) == 1:
remediation = fmt.Sprintf("Try running the command with the `--%s` flag included\nLearn more about this flag with `--help`", flags[0].Name)
case len(flags) > 1:
Expand All @@ -290,6 +292,13 @@ func errInteractivityFlags(cfg PromptConfig, message string, options []string) e
WithRemediation("%s", remediation)
}

// isPasswordPrompt reports whether the prompt collects a secret, such as a
// token or a password, that is safer typed than passed as a flag.
func isPasswordPrompt(cfg PromptConfig) bool {
_, ok := cfg.(PasswordPromptConfig)
return ok
}

// ConfirmPrompt prompts the user for a "yes" or "no" (true or false) value for
// the message
func (io *IOStreams) ConfirmPrompt(ctx context.Context, message string, cfg ConfirmPromptConfig) (bool, error) {
Expand Down
12 changes: 11 additions & 1 deletion internal/iostreams/prompts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,20 @@ func TestErrInteractivityFlags(t *testing.T) {
contains: []string{"not a TTY"},
},
"one flag suggests the flag name": {
cfg: SelectPromptConfig{
Flag: &pflag.Flag{Name: "team"},
},
contains: []string{"Try running the command with the `--team` flag included"},
},
"password flag suggests an interactive terminal first": {
cfg: PasswordPromptConfig{
Flag: &pflag.Flag{Name: "token"},
},
contains: []string{"--token"},
contains: []string{
"Run this command in an interactive terminal to enter the value with hidden input",
"The `--token` flag also works, but can leave the value in shell history",
},
excludes: []string{"Try running the command with"},
},
"multiple flags lists all flag names": {
cfg: SelectPromptConfig{Flags: []*pflag.Flag{
Expand Down
Loading