diff options
Diffstat (limited to 'example_test.go')
| -rw-r--r-- | example_test.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/example_test.go b/example_test.go index 72807a7..eb8d315 100644 --- a/example_test.go +++ b/example_test.go @@ -135,3 +135,40 @@ func Example_usageString() { // optimization level // --help, -h display this help and exit } + +// This example shows the usage string generated by go-arg +func Example_usageStringWithSubcommand() { + // These are the args you would pass in on the command line + os.Args = split("./example --help") + + type getCmd struct { + Item string `arg:"positional" help:"item to fetch"` + } + + type listCmd struct { + Format string `help:"output format"` + Limit int + } + + var args struct { + Verbose bool + Get *getCmd `arg:"subcommand" help:"fetch an item and print it"` + List *listCmd `arg:"subcommand" help:"list available items"` + } + + // This is only necessary when running inside golang's runnable example harness + osExit = func(int) {} + + MustParse(&args) + + // output: + // Usage: example [--verbose] + // + // Options: + // --verbose + // --help, -h display this help and exit + // + // Commands: + // get fetch an item and print it + // list list available items +} |
