diff options
| author | Alex Flint <[email protected]> | 2021-04-16 21:03:14 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-04-16 21:03:14 -0700 |
| commit | f4eb7f3a585abd65b0568428b2b9fde8cebffb6a (patch) | |
| tree | 8710075d4a458bdb31880d7a68f143c3b7a53108 /usage_test.go | |
| parent | 113aef7114af6135372272d6bb8ac4ceaf3a7a79 (diff) | |
| parent | 172800ff9a2765185520c06dcf969fde9f5eb5e3 (diff) | |
Merge pull request #137 from alexflint/optional-long
Optional long names
Diffstat (limited to 'usage_test.go')
| -rw-r--r-- | usage_test.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/usage_test.go b/usage_test.go index 5d379a1..6dee402 100644 --- a/usage_test.go +++ b/usage_test.go @@ -309,3 +309,61 @@ Global options: p.WriteHelp(&help) assert.Equal(t, expectedHelp, help.String()) } + +func TestUsageWithoutLongNames(t *testing.T) { + expectedHelp := `Usage: example [-a PLACEHOLDER] -b SHORTONLY2 + +Options: + -a PLACEHOLDER some help [default: some val] + -b SHORTONLY2 some help2 + --help, -h display this help and exit +` + var args struct { + ShortOnly string `arg:"-a,--" help:"some help" default:"some val" placeholder:"PLACEHOLDER"` + ShortOnly2 string `arg:"-b,--,required" help:"some help2"` + } + p, err := NewParser(Config{Program: "example"}, &args) + assert.NoError(t, err) + var help bytes.Buffer + p.WriteHelp(&help) + assert.Equal(t, expectedHelp, help.String()) +} + +func TestUsageWithShortFirst(t *testing.T) { + expectedHelp := `Usage: example [-c CAT] [--dog DOG] + +Options: + -c CAT + --dog DOG + --help, -h display this help and exit +` + var args struct { + Dog string + Cat string `arg:"-c,--"` + } + p, err := NewParser(Config{Program: "example"}, &args) + assert.NoError(t, err) + var help bytes.Buffer + p.WriteHelp(&help) + assert.Equal(t, expectedHelp, help.String()) +} + +func TestUsageWithEnvOptions(t *testing.T) { + expectedHelp := `Usage: example [-s SHORT] + +Options: + -s SHORT [env: SHORT] + --help, -h display this help and exit +` + var args struct { + Short string `arg:"--,-s,env"` + EnvOnly string `arg:"--,env"` + EnvOnlyOverriden string `arg:"--,env:CUSTOM"` + } + + p, err := NewParser(Config{Program: "example"}, &args) + assert.NoError(t, err) + var help bytes.Buffer + p.WriteHelp(&help) + assert.Equal(t, expectedHelp, help.String()) +} |
