diff options
| author | Alex Flint <[email protected]> | 2020-02-23 11:51:43 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-02-23 11:51:43 -0800 |
| commit | ce4cd0ce03f9d0ca40a3090a63997bfaf6757aaa (patch) | |
| tree | 3e3d4cc02b32531c414f8f493cd7bffb9fea917b /usage_test.go | |
| parent | 82c2a36dd78d06fa6391033942bdd7f14ce07704 (diff) | |
| parent | c24567c12e7036f9f18c62ea13bb85b84e3d80ff (diff) | |
Merge pull request #106 from dallbee/subcommand-usage
Subcommand usage options
Diffstat (limited to 'usage_test.go')
| -rw-r--r-- | usage_test.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/usage_test.go b/usage_test.go index d9d33f0..31b439b 100644 --- a/usage_test.go +++ b/usage_test.go @@ -266,8 +266,45 @@ Options: p, err := NewParser(Config{}, &args) require.NoError(t, err) + var help bytes.Buffer + p.WriteHelp(&help) + assert.Equal(t, expectedHelp, help.String()) +} + +func TestUsagWithNestedSubcommands(t *testing.T) { + expectedHelp := `Usage: example child nested [--enable] OUTPUT + +Positional arguments: + OUTPUT + +Options: + --enable + +Global options: + --values VALUES Values + --verbose, -v verbosity level + --help, -h display this help and exit +` + + var args struct { + Verbose bool `arg:"-v" help:"verbosity level"` + Child *struct { + Values []float64 `help:"Values"` + Nested *struct { + Enable bool + Output string `arg:"positional,required"` + } `arg:"subcommand:nested"` + } `arg:"subcommand:child"` + } + os.Args[0] = "example" + p, err := NewParser(Config{}, &args) + require.NoError(t, err) + + _ = p.Parse([]string{"child", "nested", "value"}) + var help bytes.Buffer p.WriteHelp(&help) + fmt.Println(help.String()) assert.Equal(t, expectedHelp, help.String()) } |
