summaryrefslogtreecommitdiff
path: root/example_test.go
diff options
context:
space:
mode:
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