diff --git a/cli/prompts.go b/cli/prompts.go index 8e3b538b..569cd6b1 100644 --- a/cli/prompts.go +++ b/cli/prompts.go @@ -18,7 +18,7 @@ type PromptLib interface { Prompt(label string, value string, edit bool, validator Validator) (string, error) PromptYN(m string, defaultValue bool) (bool, error) PromptSecret(m string) (string, error) - PromptChoices(m string, choices []string) (int, error) + PromptChoices(m string, value string, choices []string) (int, error) PromptMultipleChoices(m string, choices []string) ([]int, error) } @@ -66,8 +66,8 @@ func PromptSecret(m string) (string, error) { return cli.PromptSecret(m) } -func PromptChoices(m string, choices []string) (int, error) { - return cli.PromptChoices(m, choices) +func PromptChoices(m string, value string, choices []string) (int, error) { + return cli.PromptChoices(m, value, choices) } func PromptMultipleChoices(m string, choices []string) ([]int, error) { diff --git a/cli/sui.go b/cli/sui.go index a9986edf..2bee41c1 100644 --- a/cli/sui.go +++ b/cli/sui.go @@ -63,12 +63,16 @@ func (sui *SurveyUI) PromptSecret(m string) (string, error) { return v, nil } -func (sui *SurveyUI) PromptChoices(m string, choices []string) (int, error) { +func (sui *SurveyUI) PromptChoices(m string, value string, choices []string) (int, error) { v := "" p := &survey.Select{ Message: m, Options: choices, } + + if value != "" { + p.Default = value + } if err := survey.AskOne(p, &v, nil); err != nil { return -1, err } diff --git a/cli/testprompts.go b/cli/testprompts.go index 4ecd8d7f..7eca1380 100644 --- a/cli/testprompts.go +++ b/cli/testprompts.go @@ -52,7 +52,7 @@ func (t *TestPrompts) PromptSecret(m string) (string, error) { return val, nil } -func (t *TestPrompts) PromptChoices(m string, choices []string) (int, error) { +func (t *TestPrompts) PromptChoices(m string, value string, choices []string) (int, error) { val := t.inputs[t.count].(int) t.count = t.count + 1 return val, nil diff --git a/cmd/addexport.go b/cmd/addexport.go index 73cfcb79..03d3babc 100644 --- a/cmd/addexport.go +++ b/cmd/addexport.go @@ -101,7 +101,7 @@ func (p *AddExportParams) PreInteractive(ctx ActionCtx) error { } choices := []string{jwt.Stream.String(), jwt.Service.String()} - i, err := cli.PromptChoices("export type", choices) + i, err := cli.PromptChoices("export type", p.export.Type.String(), choices) if err != nil { return err } diff --git a/cmd/deleteexport.go b/cmd/deleteexport.go index 696697b8..e8602329 100644 --- a/cmd/deleteexport.go +++ b/cmd/deleteexport.go @@ -111,7 +111,7 @@ func (p *DeleteExportParams) PostInteractive(ctx ActionCtx) error { for _, c := range p.claim.Exports { choices = append(choices, fmt.Sprintf("[%s] %s - %s", c.Type, c.Name, c.Subject)) } - p.index, err = cli.PromptChoices("select export to delete", choices) + p.index, err = cli.PromptChoices("select export to delete", "", choices) if err != nil { return err } diff --git a/cmd/deleteimport.go b/cmd/deleteimport.go index c44612da..bddadb94 100644 --- a/cmd/deleteimport.go +++ b/cmd/deleteimport.go @@ -114,7 +114,7 @@ func (p *DeleteImportParams) PostInteractive(ctx ActionCtx) error { for _, c := range p.claim.Imports { choices = append(choices, fmt.Sprintf("[%s] %s - %s", c.Type, c.Name, c.Subject)) } - p.index, err = cli.PromptChoices("select import to delete", choices) + p.index, err = cli.PromptChoices("select import to delete", "", choices) if err != nil { return err } diff --git a/cmd/generateactivation.go b/cmd/generateactivation.go index c9f5025a..7601a7e0 100644 --- a/cmd/generateactivation.go +++ b/cmd/generateactivation.go @@ -149,7 +149,7 @@ func (p *GenerateActivationParams) PostInteractive(ctx ActionCtx) error { choices = append(choices, fmt.Sprintf("[%s] %s - %s", v.Type, v.Name, v.Subject)) } } - i, err := cli.PromptChoices("select export", choices) + i, err := cli.PromptChoices("select export", p.subject, choices) if err != nil { return err } diff --git a/cmd/generateoperatorconfig.go b/cmd/generateoperatorconfig.go index 9f9fadfd..9f6db46c 100644 --- a/cmd/generateoperatorconfig.go +++ b/cmd/generateoperatorconfig.go @@ -79,7 +79,7 @@ func (p *GenerateOperatorConfigParams) PreInteractive(ctx ActionCtx) error { p.name = names[0] } if len(names) > 1 { - i, err := cli.PromptChoices("select operator", names) + i, err := cli.PromptChoices("select operator", config.Operator, names) if err != nil { return err } diff --git a/cmd/init.go b/cmd/init.go index b6870409..da5ef93c 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -235,7 +235,7 @@ func (p *InitParams) Interactive(cmd *cobra.Command) error { for { p.PrintSummary(cmd) choices := []string{"Yes", "Cancel", "Edit operator", "Edit account", "Edit user", "Edit cluster", "Edit server"} - c, err := cli.PromptChoices("is this OK", choices) + c, err := cli.PromptChoices("is this OK", "Yes", choices) if err != nil { return err } diff --git a/cmd/store/store.go b/cmd/store/store.go index e12e254c..05d07df1 100644 --- a/cmd/store/store.go +++ b/cmd/store/store.go @@ -646,7 +646,7 @@ func (ctx *Context) PickAccount(name string) (string, error) { name = accounts[0] } if len(accounts) > 1 { - i, err := cli.PromptChoices("select account", accounts) + i, err := cli.PromptChoices("select account", name, accounts) if err != nil { return "", err } @@ -697,7 +697,7 @@ func (ctx *Context) PickUser(accountName string) (string, error) { return users[0], nil } if len(users) > 1 { - i, err := cli.PromptChoices("select user", users) + i, err := cli.PromptChoices("select user", "", users) if err != nil { return "", err } @@ -744,7 +744,7 @@ func (ctx *Context) PickServer(clusterName string) (string, error) { return servers[0], nil } if len(servers) > 1 { - i, err := cli.PromptChoices("select server", servers) + i, err := cli.PromptChoices("select server", "", servers) if err != nil { return "", err } @@ -769,7 +769,7 @@ func (ctx *Context) PickCluster(name string) (string, error) { name = clusters[0] } if len(clusters) > 1 { - i, err := cli.PromptChoices("select cluster", clusters) + i, err := cli.PromptChoices("select cluster", "", clusters) if err != nil { return "", err }