diff options
| author | Andrew Morozko <[email protected]> | 2019-11-29 22:33:16 +0300 |
|---|---|---|
| committer | Andrew Morozko <[email protected]> | 2019-11-29 22:33:16 +0300 |
| commit | 904e03926794663089b73d52a02def065d819200 (patch) | |
| tree | 9355b68ec30c55a81968cd92280acd0f69281dcf /example_test.go | |
| parent | c0c7a3ba8a1854cd85e65cca4f0e2028698a0738 (diff) | |
Added the "dataname" tag
Diffstat (limited to 'example_test.go')
| -rw-r--r-- | example_test.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/example_test.go b/example_test.go index f71fbeb..3f7f2ab 100644 --- a/example_test.go +++ b/example_test.go @@ -135,6 +135,42 @@ func Example_helpText() { // --help, -h display this help and exit } +// This example shows the usage string generated by go-arg with custom datanames +func Example_helpDataname() { + // These are the args you would pass in on the command line + os.Args = split("./example --help") + + var args struct { + Input string `arg:"positional,dataname:DATAFILE"` + Output []string `arg:"positional"` + Verbose bool `arg:"-v" help:"verbosity level"` + Dataset string `help:"dataset to use"` + Optimize int `arg:"-O,help:optimization level,dataname:LEVEL"` + MaxJobs int `arg:"-j,help:maximum number of simultaneous jobs,dataname:N"` + } + + // This is only necessary when running inside golang's runnable example harness + osExit = func(int) {} + + MustParse(&args) + + // output: + + // Usage: example [--verbose] [--dataset DATASET] [--optimize LEVEL] [--maxjobs N] DATAFILE [OUTPUT [OUTPUT ...]] + + // Positional arguments: + // DATAFILE + // OUTPUT + + // Options: + // --verbose, -v verbosity level + // --dataset DATASET dataset to use + // --optimize LEVEL, -O LEVEL + // optimization level + // --maxjobs N, -j N maximum number of simultanious jobs + // --help, -h display this help and exit +} + // This example shows the usage string generated by go-arg when using subcommands func Example_helpTextWithSubcommand() { // These are the args you would pass in on the command line |
