Skip to content

Commit

Permalink
add apps picker
Browse files Browse the repository at this point in the history
  • Loading branch information
cyx committed Mar 23, 2021
1 parent 38fdbee commit 09341ce
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions internal/cli/apps.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -165,9 +166,16 @@ auth0 apps show <id>
},
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
if err := appID.Ask(cmd, &inputs.ID); err != nil {
err := appID.Picker(cmd, &inputs.ID, cli.appPickerOptions)
if err != nil {
return err
}

if inputs.ID == "" {
cli.renderer.Infof("There are currently no apps.")
return nil
}

} else {
inputs.ID = args[0]
}
Expand Down Expand Up @@ -209,9 +217,16 @@ auth0 apps delete <id>
},
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
if err := appID.Ask(cmd, &inputs.ID); err != nil {
err := appID.Picker(cmd, &inputs.ID, cli.appPickerOptions)
if err != nil {
return err
}

if inputs.ID == "" {
cli.renderer.Infof("There are currently no apps.")
return nil
}

} else {
inputs.ID = args[0]
}
Expand Down Expand Up @@ -389,11 +404,17 @@ auth0 apps update <id> --name myapp --type [native|spa|regular|m2m]
RunE: func(cmd *cobra.Command, args []string) error {
var current *management.Client

// Get app id
if len(args) == 0 {
if err := appID.Ask(cmd, &inputs.ID); err != nil {
err := appID.Picker(cmd, &inputs.ID, cli.appPickerOptions)
if err != nil {
return err
}

if inputs.ID == "" {
cli.renderer.Infof("There are currently no apps.")
return nil
}

} else {
inputs.ID = args[0]
}
Expand Down Expand Up @@ -680,3 +701,26 @@ func interfaceToStringSlice(s []interface{}) []string {
}
return result
}

func (c *cli) appPickerOptions() (pickerOptions, error) {
list, err := c.api.Client.List()
if err != nil {
return nil, err
}

// NOTE: because client names are not unique, we'll just number these
// labels.
var opts pickerOptions
for _, c := range list.Clients {
value := c.GetClientID()
label := fmt.Sprintf("%s %s", c.GetName(), ansi.Faint("("+value+")"))

opts = append(opts, pickerOption{value: value, label: label})
}

if len(opts) == 0 {
return nil, errors.New("There are currently no applications.")
}

return opts, nil
}

0 comments on commit 09341ce

Please sign in to comment.