Repository: nats-io/nsc (go)

Issue:
Add user with default account set in interactive mode
It asks for account even though default set. 
At least could select default one

```
~/.nkeys/synadia/accounts/system> nsc env --account system
╭──────────────────────────────────────────╮
│             NSC Environment              │
├──────────────────┬─────┬─────────────────┤
│ Setting          │ Set │ Effective Value │
├──────────────────┼─────┼─────────────────┤
│ $NKEYS_PATH      │ No  │ ~/.nkeys        │
│ $NSC_HOME        │ No  │ ~/.nsc          │
│ Config           │     │ ~/.nsc/nsc.json │
├──────────────────┼─────┼─────────────────┤
│ Stores Dir       │     │ ~/.nsc/nats     │
│ Default Operator │     │ synadia         │
│ Default Account  │     │ system          │
│ Default Cluster  │     │                 │
╰──────────────────┴─────┴─────────────────╯

~/.nkeys/synadia/accounts/system> nsc list users
╭────────────────────────────────────────────────────────────────────────╮
│                                 Users                                  │
├─────────────┬──────────────────────────────────────────────────────────┤
│ Name        │ Public Key                                               │
├─────────────┼──────────────────────────────────────────────────────────┤
│ ngs_server  │ UCJX2PK7F3DXAYSBMGOCECSRZFIV7EVN6VCEG7KYP4FLVTRVGLCMXSKF │
│ test_system │ UBW3GQ3AGWDSYSTFQT4PYJPZF2JVQRXSSPWPMO2AZ23Z2WU2CH3SUY6I │
╰─────────────┴──────────────────────────────────────────────────────────╯

~/.nkeys/synadia/accounts/system> nsc add user -i
? user name ping_user
? generate an user nkey Yes
? select account  [Use arrows to move, type to filter]
> demos
  synadia
  system```

Pull request:
FIX #38 - default in pickers set to current value

Patch:
diff --git a/cli/prompts.go b/cli/prompts.go
index 8e3b538..569cd6b 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 a9986ed..2bee41c 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/cmd/addexport.go b/cmd/addexport.go
index 73cfcb7..03d3bab 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 696697b..e860232 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 c44612d..bddadb9 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 c9f5025..7601a7e 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 9f9fadf..9f6db46 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 b687040..da5ef93 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 e12e254..05d07df 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
 		}


Test patch:
diff --git a/cli/testprompts.go b/cli/testprompts.go
index 4ecd8d7..7eca138 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