diff options
| author | Alex Flint <[email protected]> | 2019-05-03 15:02:10 -0700 |
|---|---|---|
| committer | Alex Flint <[email protected]> | 2019-05-03 15:02:10 -0700 |
| commit | 15bf383f1d5db9bf362029529f3c83f092e2d00f (patch) | |
| tree | 8cb7448834eacb0039546a5b10d896af11437400 /example_test.go | |
| parent | edd1af466781355875c44cd9213ce1e398a4c84d (diff) | |
add subcommands to usage string
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 +} |
