-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcounted_example.go
61 lines (48 loc) · 1.43 KB
/
counted_example.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
package main
import (
"fmt"
"github.com/WindomZ/go-commander"
)
func main() {
// ----------- go-commander -----------
// counted_example -v...
commander.Program.
Option("-v...", "", func(c commander.Context) {
fmt.Println("-v =", c.Get("-v"))
})
// counted_example go [go]
commander.Program.
Command("go [go]").
Action(func(c commander.Context) {
fmt.Println("go =", c.Get("go"))
})
// counted_example (--path=<path>)...
commander.Program.
Command("(--path=<path>)...", "", func(c commander.Context) {
fmt.Printf("--path = %q\n",
c.MustStrings("--path"))
})
// counted_example <file> <file>
commander.Program.
Command("<file> <file>", "", func(c commander.Context) {
fmt.Printf("<file> = %q\n",
c.MustStrings("<file>"))
})
commander.Program.Parse()
//fmt.Println(commander.Program.HelpMessage()) // print help messages
fmt.Println("-------------")
// ----------- docopt-go -----------
usage := `Usage: counted_example --help
counted_example -v...
counted_example go [go]
counted_example (--path=<path>)...
counted_example <file> <file>
Try: counted_example -vvvvvvvvvv
counted_example go go
counted_example --path ./here --path ./there
counted_example this.txt that.txt`
arguments, _ := commander.Parse(usage, nil, true, "", false)
//fmt.Println(usage) // print help messages
fmt.Println(arguments)
fmt.Println("===============================")
}