-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_test.go
64 lines (48 loc) · 1.41 KB
/
app_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
package gocli
import (
"fmt"
)
// Examples -------------------------------------------------------------------
func ExampleApp() {
// Create the root App object.
app := NewApp("app")
app.Short = "my bloody gocli app"
app.Version = "1.2.3"
app.Long = `
This is a long description of my super uber cool app.`
// A verbose switch flag.
var verbose bool
// Create a subcommand.
var subcmd = &Command{
UsageLine: "subcmd [-v]",
Short: "some kind of subcommand, you name it",
Long: "Brb, too tired to write long descriptions.",
Action: func(cmd *Command, args []string) {
fmt.Printf("verbose mode set to %t\n", verbose)
},
}
// Set up the verbose switch. This can be as well called in init() or so.
subcmd.Flags.BoolVar(&verbose, "v", false, "print verbose output")
// Register the command with the parent command. Also suitable for init().
app.MustRegisterSubcommand(subcmd)
/*
Run the whole thing.
app.Run([]string{}) would lead into:
APPLICATION:
app - my bloody gocli app
OPTIONS:
-h=false: print help and exit
VERSION:
1.2.3
DESCRIPTION:
This is a long description of my super uber cool app.
SUBCOMMANDS:
subcmd some kind of subcommand, you name it
, app.Run([]string{"subcmd", "-h"}) into something similar.
*/
app.Run([]string{"subcmd"})
app.Run([]string{"subcmd", "-v"})
// Output:
// verbose mode set to false
// verbose mode set to true
}