-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_help_test.go
70 lines (60 loc) · 1.97 KB
/
example_help_test.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
63
64
65
66
67
68
69
70
package cliargs_test
import (
"fmt"
"github.com/sttk/cliargs"
)
func ExampleHelp_Print() {
type MyOptions struct {
FooBar bool `optcfg:"foo-bar,f" optdesc:"FooBar is a flag.\nThis flag is foo bar."`
Baz int `optcfg:"baz,b=99" optdesc:"Baz is a integer." optarg:"<num>"`
Qux string `optcfg:"=XXX" optdesc:"Qux is a string." optarg:"<text>"`
Quux []string `optcfg:"quux=[A,B,C]" optdesc:"Quux is a string array."`
}
options := MyOptions{}
optCfgs, _ := cliargs.MakeOptCfgsFor(&options)
help := cliargs.NewHelpWithMargins(5, 2)
help.AddText("This is the usage section.")
help.AddOptsWithIndentAndMargins(optCfgs, 10, 1, 0)
help.Print()
// Output:
// This is the usage section.
// --foo-bar, -f
// FooBar is a flag.
// This flag is foo bar.
// --baz, -b <num>
// Baz is a integer.
// --Qux <text>
// Qux is a string.
// --quux Quux is a string array.
}
func ExampleHelp_Iter() {
type MyOptions struct {
FooBar bool `optcfg:"foo-bar,f" optdesc:"FooBar is a flag.\nThis flag is foo bar."`
Baz int `optcfg:"baz,b=99" optdesc:"Baz is a integer." optarg:"<num>"`
Qux string `optcfg:"=XXX" optdesc:"Qux is a string." optarg:"<text>"`
Quux []string `optcfg:"quux=[A,B,C]" optdesc:"Quux is a string array."`
}
options := MyOptions{}
optCfgs, _ := cliargs.MakeOptCfgsFor(&options)
help := cliargs.NewHelpWithMargins(5, 2)
help.AddText("This is the usage section.")
help.AddOptsWithIndentAndMargins(optCfgs, 10, 1, 0)
iter := help.Iter()
for {
line, exists := iter.Next()
if !exists {
break
}
fmt.Println(line)
}
// Output:
// This is the usage section.
// --foo-bar, -f
// FooBar is a flag.
// This flag is foo bar.
// --baz, -b <num>
// Baz is a integer.
// --Qux <text>
// Qux is a string.
// --quux Quux is a string array.
}