-
Notifications
You must be signed in to change notification settings - Fork 1
/
quick_example.go
57 lines (46 loc) · 1.4 KB
/
quick_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
package main
import (
"fmt"
"github.com/WindomZ/go-commander"
)
func main() {
// ----------- go-commander -----------
// quick_example
commander.Program.
Version("0.1.1rc")
// quick_example tcp <host> <port> [--timeout=<seconds>]
commander.Program.
Command("tcp <host> <port>").
Option("--timeout=<seconds>").
Action(func() {
fmt.Printf("tcp %s %s %s\n",
commander.Program.MustString("<host>"),
commander.Program.MustString("<port>"),
commander.Program.MustString("--timeout"),
)
})
// quick_example serial <port> [--baud=9600] [--timeout=<seconds>]
commander.Program.
Command("serial <port>").
Option("--baud=9600").
Option("--timeout=<seconds>").
Action(func() {
fmt.Printf("serial %s %s %s\n",
commander.Program.MustString("<port>"),
commander.Program.MustString("--baud"),
commander.Program.MustString("--timeout"),
)
})
commander.Program.Parse()
//fmt.Println(commander.Program.HelpMessage()) // print help messages
fmt.Println("-------------")
// ----------- docopt-go -----------
usage := `Usage:
quick_example tcp <host> <port> [--timeout=<seconds>]
quick_example serial <port> [--baud=9600] [--timeout=<seconds>]
quick_example -h | --help | --version`
arguments, _ := commander.Parse(usage, nil, true, "0.1.1rc", false)
//fmt.Println(usage) // print help messages
fmt.Println(arguments)
fmt.Println("===============================")
}