summaryrefslogtreecommitdiff
path: root/example_test.go
diff options
context:
space:
mode:
authorAlex Flint <[email protected]>2019-12-01 01:22:05 -0800
committerGitHub <[email protected]>2019-12-01 01:22:05 -0800
commitced05bfe8a0f966d6ed09af656f5410bc5f4ed7c (patch)
tree75a1540bde1cf3b46b45854e5043ca2100638888 /example_test.go
parentc0c7a3ba8a1854cd85e65cca4f0e2028698a0738 (diff)
parent9d4521ce8be4871b3ba85cb1bfa96f4b074f505b (diff)
Merge pull request #96 from Andrew-Morozko/master
Added the "placeholder" tag
Diffstat (limited to 'example_test.go')
-rw-r--r--example_test.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/example_test.go b/example_test.go
index f71fbeb..ea123e4 100644
--- a/example_test.go
+++ b/example_test.go
@@ -135,6 +135,38 @@ func Example_helpText() {
// --help, -h display this help and exit
}
+// This example shows the usage string generated by go-arg with customized placeholders
+func Example_helpPlaceholder() {
+ // These are the args you would pass in on the command line
+ os.Args = split("./example --help")
+
+ var args struct {
+ Input string `arg:"positional" placeholder:"SRC"`
+ Output []string `arg:"positional" placeholder:"DST"`
+ Optimize int `arg:"-O" help:"optimization level" placeholder:"LEVEL"`
+ MaxJobs int `arg:"-j" help:"maximum number of simultaneous jobs" placeholder:"N"`
+ }
+
+ // This is only necessary when running inside golang's runnable example harness
+ osExit = func(int) {}
+
+ MustParse(&args)
+
+ // output:
+
+ // Usage: example [--optimize LEVEL] [--maxjobs N] SRC [DST [DST ...]]
+
+ // Positional arguments:
+ // SRC
+ // DST
+
+ // Options:
+ // --optimize LEVEL, -O LEVEL
+ // optimization level
+ // --maxjobs N, -j N maximum number of simultaneous 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