-
Notifications
You must be signed in to change notification settings - Fork 4
/
runners.go
62 lines (51 loc) · 1.77 KB
/
runners.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package prompt
import (
"github.com/cqroot/prompt/choose"
"github.com/cqroot/prompt/input"
"github.com/cqroot/prompt/multichoose"
"github.com/cqroot/prompt/write"
)
// Choose lets the user choose one of the given choices.
func (p Prompt) Choose(choices []string, opts ...choose.Option) (string, error) {
pm := choose.NewWithStrings(choices, opts...)
m, err := p.Run(*pm, append(p.teaProgramOpts, pm.TeaProgramOpts()...)...)
if err != nil {
return "", err
}
return m.(choose.Model).Data(), nil
}
// Choose lets the user choose one of the given choices.
func (p Prompt) AdvancedChoose(choices []choose.Choice, opts ...choose.Option) (string, error) {
pm := choose.New(choices, opts...)
m, err := p.Run(*pm, append(p.teaProgramOpts, pm.TeaProgramOpts()...)...)
if err != nil {
return "", err
}
return m.(choose.Model).Data(), nil
}
// MultiChoose lets the user choose multiples from the given choices.
func (p Prompt) MultiChoose(choices []string, opts ...multichoose.Option) ([]string, error) {
pm := multichoose.New(choices, opts...)
m, err := p.Run(*pm, append(p.teaProgramOpts, pm.TeaProgramOpts()...)...)
if err != nil {
return nil, err
}
return m.(multichoose.Model).Data(), nil
}
// Input asks the user to enter a string.
func (p Prompt) Input(defaultValue string, opts ...input.Option) (string, error) {
pm := input.New(defaultValue, opts...)
m, err := p.Run(*pm, append(p.teaProgramOpts, pm.TeaProgramOpts()...)...)
if err != nil {
return "", err
}
return m.(input.Model).Data(), nil
}
func (p Prompt) Write(defaultValue string, opts ...write.Option) (string, error) {
pm := write.New(defaultValue, opts...)
m, err := p.Run(*pm, append(p.teaProgramOpts, pm.TeaProgramOpts()...)...)
if err != nil {
return "", err
}
return m.(write.Model).Data(), nil
}