diff options
| author | Alex Flint <[email protected]> | 2024-03-31 10:30:12 -0400 |
|---|---|---|
| committer | Alex Flint <[email protected]> | 2024-03-31 10:30:12 -0400 |
| commit | 8e35a4f0d4616f11c322e63dc3ad373fe3d25e0d (patch) | |
| tree | 1ceb580758694cccba16ccac32da825606f5108c /usage_test.go | |
| parent | 5ec29ce7553bbbe81d99f0900df072eea56b945e (diff) | |
handle explicit empty placeholders
Diffstat (limited to 'usage_test.go')
| -rw-r--r-- | usage_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/usage_test.go b/usage_test.go index 1a64ad4..1e2aca4 100644 --- a/usage_test.go +++ b/usage_test.go @@ -522,6 +522,35 @@ Options: assert.Equal(t, expectedUsage, strings.TrimSpace(usage.String())) } +func TestUsageWithEmptyPlaceholder(t *testing.T) { + expectedUsage := "Usage: example [-a] [--b] [--c]" + + expectedHelp := ` +Usage: example [-a] [--b] [--c] + +Options: + -a some help for a + --b some help for b + --c, -c some help for c + --help, -h display this help and exit +` + var args struct { + ShortOnly string `arg:"-a,--" placeholder:"" help:"some help for a"` + LongOnly string `arg:"--b" placeholder:"" help:"some help for b"` + Both string `arg:"-c,--c" placeholder:"" help:"some help for c"` + } + p, err := NewParser(Config{Program: "example"}, &args) + require.NoError(t, err) + + var help bytes.Buffer + p.WriteHelp(&help) + assert.Equal(t, expectedHelp[1:], help.String()) + + var usage bytes.Buffer + p.WriteUsage(&usage) + assert.Equal(t, expectedUsage, strings.TrimSpace(usage.String())) +} + func TestUsageWithShortFirst(t *testing.T) { expectedUsage := "Usage: example [-c CAT] [--dog DOG]" |
