-
Notifications
You must be signed in to change notification settings - Fork 55
/
input.go
41 lines (31 loc) · 933 Bytes
/
input.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package cli
import (
"fmt"
"github.com/auth0/auth0-cli/internal/prompt"
"github.com/spf13/cobra"
)
type commandInput interface {
GetName() string
GetLabel() string
GetHelp() string
GetIsRequired() bool
}
func ask(cmd *cobra.Command, i commandInput, value interface{}, isUpdate bool) error {
isRequired := !isUpdate && i.GetIsRequired()
input := prompt.TextInput("", i.GetLabel(), i.GetHelp(), isRequired)
if err := prompt.AskOne(input, value); err != nil {
return unexpectedError(err)
}
return nil
}
func _select(cmd *cobra.Command, i commandInput, value interface{}, options []string, isUpdate bool) error {
isRequired := !isUpdate && i.GetIsRequired()
input := prompt.SelectInput("", i.GetLabel(), i.GetHelp(), options, isRequired)
if err := prompt.AskOne(input, value); err != nil {
return unexpectedError(err)
}
return nil
}
func inputLabel(name string) string {
return fmt.Sprintf("%s:", name)
}