-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
41 lines (33 loc) · 954 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
//go:build ignore
// this is show case for creating arguments by batch
package main
import (
"fmt"
"github.com/hellflame/argparse"
)
func main() {
p := argparse.NewParser("", "example to batch create arguments", nil)
nameArgs := make(map[string]*string)
for _, n := range []string{"firstName", "midName", "lastName"} {
nameArgs[n] = p.String("", n, &argparse.Option{Help: "this is part of your name", Group: "Names"})
}
statusArgs := make(map[string]*bool)
for _, s := range []string{"employed", "graduated", "merried", "divorced", "underage", "crazy", "happy"} {
statusArgs[s] = p.Flag("", s, &argparse.Option{Help: fmt.Sprintf("are you %s?", s)})
}
if e := p.Parse(nil); e != nil {
switch e.(type) {
case argparse.BreakAfterHelp:
return
default:
fmt.Println(e.Error())
return
}
}
for arg, bind := range nameArgs {
fmt.Println(arg, *bind)
}
for arg, bind := range statusArgs {
fmt.Println(arg, *bind)
}
}