diff options
| author | Alex Flint <[email protected]> | 2023-10-08 20:09:05 -0400 |
|---|---|---|
| committer | Alex Flint <[email protected]> | 2023-10-08 20:09:05 -0400 |
| commit | 0142b0b842fe99530778d06cab696b76d13b9024 (patch) | |
| tree | 2d990f1295b5e9e93cc8bea6ef6ea14881836ca0 /usage_test.go | |
| parent | 5ec29ce7553bbbe81d99f0900df072eea56b945e (diff) | |
add subcommand aliases
Diffstat (limited to 'usage_test.go')
| -rw-r--r-- | usage_test.go | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/usage_test.go b/usage_test.go index 1a64ad4..b1693a9 100644 --- a/usage_test.go +++ b/usage_test.go @@ -450,6 +450,8 @@ Global options: _ = p.Parse([]string{"child", "nested", "value"}) + assert.Equal(t, []string{"child", "nested"}, p.SubcommandNames()) + var help bytes.Buffer p.WriteHelp(&help) assert.Equal(t, expectedHelp[1:], help.String()) @@ -471,7 +473,7 @@ func TestNonexistentSubcommand(t *testing.T) { var args struct { sub *struct{} `arg:"subcommand"` } - p, err := NewParser(Config{}, &args) + p, err := NewParser(Config{Exit: func(int) {}}, &args) require.NoError(t, err) var b bytes.Buffer @@ -687,3 +689,29 @@ Options: p.WriteHelp(&help) assert.Equal(t, expectedHelp[1:], help.String()) } + +func TestHelpShowsSubcommandAliases(t *testing.T) { + expectedHelp := ` +Usage: example <command> [<args>] + +Options: + --help, -h display this help and exit + +Commands: + remove, rm, r remove something from somewhere + simple do something simple + halt, stop stop now +` + + var args struct { + Remove *struct{} `arg:"subcommand:remove|rm|r" help:"remove something from somewhere"` + Simple *struct{} `arg:"subcommand" help:"do something simple"` + Stop *struct{} `arg:"subcommand:halt|stop" help:"stop now"` + } + 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()) +} |
