-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnamespace_example_test.go
More file actions
60 lines (55 loc) · 1.54 KB
/
namespace_example_test.go
File metadata and controls
60 lines (55 loc) · 1.54 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
package verbs_test
import (
"fmt"
"os"
"github.com/revl/verbs"
)
var cloudCLI = &verbs.CLI{
ProgramName: "cloud",
Summary: "Manage cloud resources",
Version: "1.0.0",
OptionResolution: verbs.Global,
Options: []*verbs.Option{{
Name: "v|verbose",
Description: "Show more output",
Tag: "verbose",
}},
Namespaces: []*verbs.Namespace{{
Name: "vm",
Summary: "Virtual machine operations",
Options: []*verbs.Option{{
Name: "r|region",
Param: "REGION",
Description: "Target region",
Tag: "region",
}},
Commands: []*verbs.Command{{
Name: "create",
Summary: "Provision a VM",
Description: "Creates a VM with an image and size.",
Options: []*verbs.Option{{
Name: "i|image",
Param: "IMAGE",
Description: "Image ID",
Tag: "image",
}},
Args: []*verbs.Arg{{Name: "NAME", Tag: "name"}},
Tag: "vm-create",
}},
}},
HelpTopics: []*verbs.HelpTopic{{
Keyword: "examples",
Summary: "Try these common tasks",
Text: "cloud vm create demo --image=ubuntu --region=us-east-1",
}},
}
// This example demonstrates how to use namespaces to organize commands and
// options hierarchically. Nested commands must be prefixed with the namespace
// name on the command line in order to be resolved.
func ExampleNamespace() {
result := verbs.NewParser(cloudCLI).Parse(os.Args)
fmt.Println("Selected command:", result.Command.Tag)
for _, arg := range result.OptsAndArgs {
fmt.Printf("%v: %q\n", arg.Tag, arg.Value)
}
}