-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
85 lines (76 loc) · 2.59 KB
/
example_test.go
File metadata and controls
85 lines (76 loc) · 2.59 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package cmd
import "fmt"
// This example implements a subset of the Unix ls command’s interface.
func ExampleCmd() {
var (
long, color, all bool
hidePattern string
files []string
)
c := New("ls", func() {})
c.Summary = "List information about the FILEs (current directory by default)."
c.Details = "The LS_COLORS environment variable can be used instead of --color."
c.Flag("-l", &long, "use a long listing format")
c.Flag("--color", &color, "colorize the output")
c.Flag("-a --all", &all, "do not ignore entries starting with .")
c.String("--hide", &hidePattern, "PATTERN",
"do not list implied entries matching shell PATTERN")
c.OptionalRepeatedArg("FILE", &files)
fmt.Print(c.Help())
// Output:
// Usage: ls [OPTION]... [FILE]...
//
// List information about the FILEs (current directory by default).
//
// Options:
// -l use a long listing format
// --color colorize the output
// -a, --all do not ignore entries starting with .
// --hide PATTERN do not list implied entries matching shell PATTERN
//
// The LS_COLORS environment variable can be used instead of --color.
}
// This implements a subset of the git command’s interface.
func ExampleGroup() {
var (
path string
status struct {
short bool
pathspec []string
}
init struct {
quiet, bare bool
}
)
git := NewGroup("git")
git.Summary = "Git is a fast, scalable, distributed revision control system."
git.String("-C", &path, "PATH", "Run as if git was started in PATH.")
gitStatus := git.Command("status", func() {})
gitStatus.Summary = "Show the working tree status"
gitStatus.Flag("-s --short", &status.short, "Give the output in the short-format.")
gitStatus.OptionalRepeatedArg("PATHSPEC...", &status.pathspec)
gitInit := git.Command("init", func() {})
gitInit.Summary = "Create an empty Git repository"
gitInit.Flag("-q --quiet", &init.quiet, "Only print error and warning messages.")
gitInit.Flag("--bare", &init.bare, "Create a bare repository.")
gitRemote := git.Group("remote")
gitRemote.Summary = "Manage the set of repositories you track"
gitRemote.Command("add", func() {})
gitRemote.Command("rename", func() {})
gitRemote.Command("remove", func() {})
fmt.Print(git.Help())
// Output:
// Usage: git [OPTION] GROUP | COMMAND
//
// Git is a fast, scalable, distributed revision control system.
//
// Options:
// -C PATH Run as if git was started in PATH.
//
// Groups:
// remote Manage the set of repositories you track
//
// Commands:
// status Show the working tree status
// init Create an empty Git repository
}