Skip to content

Commit

Permalink
Add selectArgument
Browse files Browse the repository at this point in the history
  • Loading branch information
cyx committed Mar 23, 2021
1 parent 4ed6caf commit 6520c3a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions internal/cli/arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"

"github.com/auth0/auth0-cli/internal/ansi"
"github.com/auth0/auth0-cli/internal/auth0"
"github.com/auth0/auth0-cli/internal/prompt"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -46,18 +48,28 @@ func (a *Argument) Picker(cmd *cobra.Command, result *string, fn pickerOptionsFu
return err
}

// TODO(cyx): Fix this up. For now everything depends on `flag`.
f := Flag{Name: a.Name}
defaultLabel := opts.defaultLabel()
var val string
if err := selectFlag(cmd, &f, &val, opts.labels(), &defaultLabel, false); err != nil {
if err := selectArgument(cmd, a, &val, opts.labels(), &defaultLabel); err != nil {
return err
}

*result = opts.getValue(val)
return nil
}

func selectArgument(cmd *cobra.Command, a *Argument, value interface{}, options []string, defaultValue *string) error {
if canPrompt(cmd) {
input := prompt.SelectInput("", a.GetLabel(), a.GetHelp(), options, auth0.StringValue(defaultValue), true)

if err := prompt.AskOne(input, value); err != nil {
return handleInputError(err)
}
}

return nil
}

func askArgument(cmd *cobra.Command, i commandInput, value interface{}) error {
if canPrompt(cmd) {
return ask(cmd, i, value, nil, true)
Expand Down

0 comments on commit 6520c3a

Please sign in to comment.