summaryrefslogtreecommitdiff
path: root/usage_test.go
diff options
context:
space:
mode:
authorRick <[email protected]>2017-10-02 14:18:41 +0100
committerRick <[email protected]>2017-10-02 14:18:41 +0100
commitd7961941f0ceee4e55062041991de7bbd43b2b57 (patch)
tree8eb798350d16f89ebfceca8b22011427c69b2289 /usage_test.go
parent398a01ebab8b6260be8714a39ad19ecb0db58dc1 (diff)
Altered help tag parsing to reduce the constraints on help text content; old behaviour is retained for backward compatibility
Diffstat (limited to 'usage_test.go')
-rw-r--r--usage_test.go45
1 files changed, 34 insertions, 11 deletions
diff --git a/usage_test.go b/usage_test.go
index 1bb1071..bdf4ea2 100644
--- a/usage_test.go
+++ b/usage_test.go
@@ -33,15 +33,15 @@ Options:
`
var args struct {
Input string `arg:"positional"`
- Output []string `arg:"positional,help:list of outputs"`
- Name string `arg:"help:name to use"`
- Value int `arg:"help:secret value"`
- Verbose bool `arg:"-v,help:verbosity level"`
- Dataset string `arg:"help:dataset to use"`
- Optimize int `arg:"-O,help:optimization level"`
- Ids []int64 `arg:"help:Ids"`
- Values []float64 `arg:"help:Values"`
- Workers int `arg:"-w,env:WORKERS,help:number of workers to start"`
+ Output []string `arg:"positional" help:"list of outputs"`
+ Name string `help:"name to use"`
+ Value int `help:"secret value"`
+ Verbose bool `arg:"-v" help:"verbosity level"`
+ Dataset string `help:"dataset to use"`
+ Optimize int `arg:"-O" help:"optimization level"`
+ Ids []int64 `help:"Ids"`
+ Values []float64 `help:"Values"`
+ Workers int `arg:"-w,env:WORKERS" help:"number of workers to start"`
}
args.Name = "Foo Bar"
args.Value = 42
@@ -60,7 +60,7 @@ Options:
assert.Equal(t, expectedHelp, help.String())
}
-func TestUsageLongPositionalWithHelp(t *testing.T) {
+func TestUsageLongPositionalWithHelp_legacyForm(t *testing.T) {
expectedHelp := `Usage: example VERYLONGPOSITIONALWITHHELP
Positional arguments:
@@ -83,6 +83,29 @@ Options:
assert.Equal(t, expectedHelp, help.String())
}
+func TestUsageLongPositionalWithHelp_newForm(t *testing.T) {
+ expectedHelp := `Usage: example VERYLONGPOSITIONALWITHHELP
+
+Positional arguments:
+ VERYLONGPOSITIONALWITHHELP
+ this positional argument is very long
+
+Options:
+ --help, -h display this help and exit
+`
+ var args struct {
+ VeryLongPositionalWithHelp string `arg:"positional" help:"this positional argument is very long"`
+ }
+
+ p, err := NewParser(Config{}, &args)
+ require.NoError(t, err)
+
+ os.Args[0] = "example"
+ var help bytes.Buffer
+ p.WriteHelp(&help)
+ assert.Equal(t, expectedHelp, help.String())
+}
+
func TestUsageWithProgramName(t *testing.T) {
expectedHelp := `Usage: myprogram
@@ -168,7 +191,7 @@ Options:
--help, -h display this help and exit
`
var args struct {
- RequiredMultiple []string `arg:"positional,required,help:required multiple positional"`
+ RequiredMultiple []string `arg:"positional,required" help:"required multiple positional"`
}
p, err := NewParser(Config{}, &args)