Skip to content

Commit

Permalink
FIX #38 - default in pickers set to current value (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart authored Dec 8, 2018
1 parent 1e3ccb7 commit 687f8a5
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 15 deletions.
6 changes: 3 additions & 3 deletions cli/prompts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion cli/sui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cli/testprompts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/addexport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/deleteexport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/deleteimport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/generateactivation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/generateoperatorconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 687f8a5

Please sign in to comment.