-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_print-help_test.go
67 lines (59 loc) · 1.93 KB
/
example_print-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
package cliargs_test
import (
"fmt"
"github.com/sttk-go/cliargs"
)
func ExamplePrintHelp() {
type MyOptions struct {
FooBar bool `opt:"foo-bar,f" optdesc:"FooBar is a flag.\nThis flag is foo bar."`
Baz int `opt:"baz,b=99" optdesc:"Baz is a integer."`
Qux string `opt:"=XXX" optdesc:"Qux is a string."`
Quux []string `opt:"quux=[A,B,C]" optdesc:"Quux is a string array."`
}
options := MyOptions{}
optCfgs, _ := cliargs.MakeOptCfgsFor(&options)
wrapOpts := cliargs.WrapOpts{MarginLeft: 5, MarginRight: 2, Indent: 10}
usage := "This is the usage section."
err := cliargs.PrintHelp(usage, optCfgs, wrapOpts)
fmt.Printf("\nerr = %v\n", err)
// Output:
// This is the usage section.
// --foo-bar, -f
// FooBar is a flag.
// This flag is foo bar.
// --baz, -b
// Baz is a integer.
// --Qux Qux is a string.
// --quux Quux is a string array.
//
// err = <nil>
}
func ExampleMakeHelp() {
type MyOptions struct {
FooBar bool `opt:"foo-bar,f" optdesc:"FooBar is a flag.\nThis flag is foo bar."`
Baz int `opt:"baz,b=99" optdesc:"Baz is a integer."`
Qux string `opt:"=XXX" optdesc:"Qux is a string."`
Quux []string `opt:"quux=[A,B,C]" optdesc:"Quux is a string array."`
}
options := MyOptions{}
optCfgs, _ := cliargs.MakeOptCfgsFor(&options)
wrapOpts := cliargs.WrapOpts{MarginLeft: 5, MarginRight: 2}
usage := "This is the usage section."
iter, err := cliargs.MakeHelp(usage, optCfgs, wrapOpts)
fmt.Printf("\nerr = %v\n", err)
for {
line, status := iter.Next()
fmt.Println(line)
if status == cliargs.ITER_NO_MORE {
break
}
}
// Output:
// err = <nil>
// This is the usage section.
// --foo-bar, -f FooBar is a flag.
// This flag is foo bar.
// --baz, -b Baz is a integer.
// --Qux Qux is a string.
// --quux Quux is a string array.
}