Skip to content

Commit

Permalink
Change CLI prompt message and type (#1516)
Browse files Browse the repository at this point in the history
Signed-off-by: Radoslav Dimitrov <[email protected]>
  • Loading branch information
rdimitrov authored Nov 6, 2023
1 parent 8b225a2 commit cb52629
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 20 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 @@ -58,10 +58,11 @@ var auth_deleteCmd = &cobra.Command{
// Confirm user wants to delete their account
yes := cli.PrintYesNoPrompt(cmd,
fmt.Sprintf(
"Are you sure you want to permanently delete your account? (yes/no): \n\nName: %s\nEmail: %s",
"You are about to permanently delete your account. \n\nName: %s\nEmail: %s",
userDetails.Name,
userDetails.Email,
),
"Are you sure?",
"Delete account operation cancelled.")
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 @@ -56,7 +56,8 @@ var Auth_revokeproviderCmd = &cobra.Command{

if all {
yes := cli.PrintYesNoPrompt(cmd,
"Are you sure you want to revoke all access tokens for your provider? (yes/no): ",
"You are about to revoke the access tokens for your provider.",
"Are you sure?",
"Delete provider access tokens cancelled.")
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 @@ -135,7 +135,8 @@ actions such as adding repositories.`,
ownerPromptStr = fmt.Sprintf("the %s organisation", owner)
}
yes := cli.PrintYesNoPrompt(cmd,
fmt.Sprintf("You are about to enroll repositories from %s. Confirm? (yes/no): \n", ownerPromptStr),
fmt.Sprintf("You are about to enroll repositories from %s.", ownerPromptStr),
"Do you confirm?",
"Enroll operation cancelled.")
if !yes {
return
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 @@ -56,7 +56,8 @@ minder control plane.`,
if deleteAll {
// Ask for confirmation if deleteAll is set on purpose
yes := cli.PrintYesNoPrompt(cmd,
"Are you sure you want to permanently delete all of your rule types? (yes/no): ",
"You are about to permanently delete all of your rule types.",
"Are you sure?",
"Delete all rule types operation cancelled.")
if !yes {
return
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/charmbracelet/bubbles v0.16.1
github.com/charmbracelet/glamour v0.6.0
github.com/charmbracelet/lipgloss v0.9.1
github.com/erikgeiser/promptkit v0.9.0
github.com/evanphx/json-patch/v5 v5.7.0
github.com/fergusstrange/embedded-postgres v1.24.0
github.com/go-git/go-billy/v5 v5.5.0
Expand Down Expand Up @@ -69,6 +70,7 @@ require (
)

require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aws/aws-sdk-go-v2/service/ecr v1.15.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ecrpublic v1.12.0 // indirect
github.com/awslabs/amazon-ecr-credential-helper/ecr-login v0.0.0-20220228164355-396b2034c795 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkY
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aws/aws-sdk-go v1.45.26 h1:PJ2NJNY5N/yeobLYe1Y+xLdavBi67ZI8gvph6ftwVCg=
github.com/aws/aws-sdk-go v1.45.26/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go-v2 v1.7.1/go.mod h1:L5LuPC1ZgDr2xQS7AmIec/Jlc7O/Y1u2KxJyNVab250=
Expand Down Expand Up @@ -358,6 +360,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA=
github.com/envoyproxy/protoc-gen-validate v1.0.2/go.mod h1:GpiZQP3dDbg4JouG/NNS7QWXpgx6x8QiMKdmN72jogE=
github.com/erikgeiser/promptkit v0.9.0 h1:3qL1mS/ntCrXdb8sTP/ka82CJ9kEQaGuYXNrYJkWYBc=
github.com/erikgeiser/promptkit v0.9.0/go.mod h1:pU9dtogSe3Jlc2AY77EP7R4WFP/vgD4v+iImC83KsCo=
github.com/evanphx/json-patch/v5 v5.7.0 h1:nJqP7uwL84RJInrohHfW0Fx3awjbm8qZeFv0nW9SYGc=
github.com/evanphx/json-patch/v5 v5.7.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
Expand Down
29 changes: 13 additions & 16 deletions internal/util/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@
package cli

import (
"bufio"
"fmt"

Check failure on line 26 in internal/util/cli/cli.go

View workflow job for this annotation

GitHub Actions / golangci-lint / Go Lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/stacklok/minder) (gci)
"io"
"os"
"strings"

"github.com/erikgeiser/promptkit/confirmation"
"github.com/spf13/cobra"
"io"

Check failure on line 29 in internal/util/cli/cli.go

View workflow job for this annotation

GitHub Actions / golangci-lint / Go Lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/stacklok/minder) (gci)
)

// PrintCmd prints a message using the output defined in the cobra Command
Expand All @@ -43,21 +40,21 @@ 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, fallbackMsg string) bool {
reader := bufio.NewReader(os.Stdin)
func PrintYesNoPrompt(cmd *cobra.Command, promptMsg, confirmMsg, fallbackMsg string) bool {
// Print the warning banner with the prompt message
PrintCmd(cmd, WarningBanner.Render(promptMsg))

// Read the response
response, _ := reader.ReadString('\n')
// Prompt the user for confirmation
input := confirmation.New(confirmMsg, confirmation.No)
ok, err := input.RunPrompt()
if err != nil {
PrintCmd(cmd, WarningBanner.Render(fmt.Sprintf("Error reading input: %v", err)))
ok = false
}

// Normalise the response
response = strings.ToLower(strings.TrimSpace(response))
if response != "yes" && response != "y" {
// Prompt was not confirmed, print the fallback message and return false
// If the user did not confirm, print the fallback message
if !ok {
PrintCmd(cmd, Header.Render(fallbackMsg))
return false
}
// Prompt was confirmed, return true
return true
return ok
}

0 comments on commit cb52629

Please sign in to comment.