Skip to content

Commit

Permalink
Add option to set default selected choice for minder prompts (#1698)
Browse files Browse the repository at this point in the history
  • Loading branch information
rdimitrov authored Nov 20, 2023
1 parent 460d9dc commit ea044f2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
3 changes: 2 additions & 1 deletion cmd/cli/app/auth/auth_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ var auth_deleteCmd = &cobra.Command{
userDetails.Email,
),
"Are you sure?",
"Delete account operation cancelled.")
"Delete account operation cancelled.",
false)
if !yes {
return
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/app/auth/auth_revoke_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ var Auth_revokeproviderCmd = &cobra.Command{
yes := cli.PrintYesNoPrompt(cmd,
"You are about to revoke the access tokens for your provider.",
"Are you sure?",
"Delete provider access tokens cancelled.")
"Delete provider access tokens cancelled.",
false)
if !yes {
return
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/app/provider/provider_enroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ func EnrollProviderCmd(cmd *cobra.Command, _ []string) (string, error) {
yes := cli.PrintYesNoPrompt(cmd,
fmt.Sprintf("You are about to enroll repositories from %s.", ownerPromptStr),
"Do you confirm?",
"Enroll operation cancelled.")
"Enroll operation cancelled.",
true)
if !yes {
return "", nil
}
Expand Down
15 changes: 10 additions & 5 deletions cmd/cli/app/quickstart/quickstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ var cmd = &cobra.Command{
yes := cli.PrintYesNoPrompt(cmd,
stepPromptMsgWelcome,
"Proceed?",
"Quickstart operation cancelled.")
"Quickstart operation cancelled.",
true)
if !yes {
return nil
}
Expand All @@ -151,7 +152,8 @@ var cmd = &cobra.Command{
yes = cli.PrintYesNoPrompt(cmd,
stepPromptMsgEnroll,
"Proceed?",
"Quickstart operation cancelled.")
"Quickstart operation cancelled.",
true)
if !yes {
return nil
}
Expand All @@ -173,7 +175,8 @@ var cmd = &cobra.Command{
yes = cli.PrintYesNoPrompt(cmd,
stepPromptMsgRegister,
"Proceed?",
"Quickstart operation cancelled.")
"Quickstart operation cancelled.",
true)
if !yes {
return nil
}
Expand All @@ -192,7 +195,8 @@ var cmd = &cobra.Command{
yes = cli.PrintYesNoPrompt(cmd,
stepPromptMsgRuleType,
"Proceed?",
"Quickstart operation cancelled.")
"Quickstart operation cancelled.",
true)
if !yes {
return nil
}
Expand Down Expand Up @@ -244,7 +248,8 @@ var cmd = &cobra.Command{
yes = cli.PrintYesNoPrompt(cmd,
fmt.Sprintf(stepPromptMsgProfile, strings.Join(registeredRepos[:], "\n")),
"Proceed?",
"Quickstart operation cancelled.")
"Quickstart operation cancelled.",
true)
if !yes {
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/app/rule_type/rule_type_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ minder control plane.`,
yes := cli.PrintYesNoPrompt(cmd,
"You are about to permanently delete all of your rule types.",
"Are you sure?",
"Delete all rule types operation cancelled.")
"Delete all rule types operation cancelled.",
false)
if !yes {
return
}
Expand Down
10 changes: 8 additions & 2 deletions internal/util/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ func Print(out io.Writer, msg string, args ...interface{}) {
}

// PrintYesNoPrompt prints a yes/no prompt to the user and returns false if the user did not respond with yes or y
func PrintYesNoPrompt(cmd *cobra.Command, promptMsg, confirmMsg, fallbackMsg string) bool {
func PrintYesNoPrompt(cmd *cobra.Command, promptMsg, confirmMsg, fallbackMsg string, defaultYes bool) bool {
// Print the warning banner with the prompt message
PrintCmd(cmd, WarningBanner.Render(promptMsg))

// Determine the default confirmation value
defConf := confirmation.No
if defaultYes {
defConf = confirmation.Yes
}

// Prompt the user for confirmation
input := confirmation.New(confirmMsg, confirmation.No)
input := confirmation.New(confirmMsg, defConf)
ok, err := input.RunPrompt()
if err != nil {
PrintCmd(cmd, WarningBanner.Render(fmt.Sprintf("Error reading input: %v", err)))
Expand Down

0 comments on commit ea044f2

Please sign in to comment.