forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsurvey.go
More file actions
85 lines (78 loc) · 1.66 KB
/
survey.go
File metadata and controls
85 lines (78 loc) · 1.66 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package iapi
import (
"fmt"
"sort"
"github.com/AlecAivazis/survey/v2"
)
func queryTypeSurvey(opts []string) (string, error) {
sort.Strings(opts)
var result string
q := &survey.Select{
Message: "Object to query",
Options: opts,
}
err := survey.AskOne(q, &result)
return result, err
}
func nextSurvey() (string, error) {
var result string
q := &survey.Select{
Message: "What is next",
Options: []string{"Add arguments", "Add fields", "Show query", "Run query", "Exit"},
}
err := survey.AskOne(q, &result)
return result, err
}
func objectsSurvey(opts []string) (string, error) {
sort.Strings(opts)
var result string
q := &survey.Select{
Message: "Object to modify",
Options: opts,
}
err := survey.AskOne(q, &result)
return result, err
}
func fieldsSurvey(opts []string) ([]string, error) {
if len(opts) == 0 {
fmt.Println("No fields available")
return nil, nil
}
sort.Strings(opts)
var result []string
q := &survey.MultiSelect{
Message: "Fields to retrieve",
Options: opts,
}
err := survey.AskOne(q, &result)
return result, err
}
func argumentsSurvey(opts []string) (map[string]string, error) {
if len(opts) == 0 {
fmt.Println("No arguments available")
return nil, nil
}
r := make(map[string]string)
var results []string
arguments := &survey.MultiSelect{
Message: "Arguments to specify",
Options: opts,
}
err := survey.AskOne(arguments, &results)
if err != nil {
return nil, err
}
for _, v := range results {
var result string
msg := fmt.Sprintf("%s", v)
argument := &survey.Input{
Message: msg,
}
err = survey.AskOne(argument, &result)
if err != nil {
return nil, err
}
r[v] = result
}
return r, nil
}