-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
44 lines (38 loc) · 896 Bytes
/
main.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
package main
import (
"errors"
"fmt"
"os"
"github.com/cqroot/prompt"
"github.com/cqroot/prompt/choose"
)
func CheckErr(err error) {
if err != nil {
if errors.Is(err, prompt.ErrUserQuit) {
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
} else {
panic(err)
}
}
}
func main() {
val1, err := prompt.New().Ask("Choose:").
AdvancedChoose([]choose.Choice{
{Text: "Item 1", Note: "The note for item 1"},
{Text: "Another item", Note: "The note for item 2"},
{Text: "Item 3", Note: "The note for item 3"},
})
CheckErr(err)
val2, err := prompt.New().Ask("Choose:").
AdvancedChoose(
[]choose.Choice{
{Text: "Item 1", Note: "The note for item 1"},
{Text: "Another item", Note: "The note for item 2"},
{Text: "Item 3", Note: "The note for item 3"},
},
choose.WithHelp(true),
)
CheckErr(err)
fmt.Printf("{ %s }, { %s }\n", val1, val2)
}