diff --git a/help_test.go b/help_test.go index 8e07aed..38080a3 100644 --- a/help_test.go +++ b/help_test.go @@ -51,7 +51,7 @@ func TestHelpOptionalArgs(t *testing.T) { assert.NoError(t, err) }) assert.True(t, exited) - expected := `Usage: test-app [ []] + expected := `Usage: test-app [ []] [flags] Arguments: [] One optional arg. @@ -105,7 +105,7 @@ func TestHelp(t *testing.T) { assert.NoError(t, err) }) assert.True(t, exited) - expected := `Usage: test-app --required + expected := `Usage: test-app --required [flags] A test app. @@ -120,13 +120,13 @@ Flags: -s, --[no-]sort Is sortable or not. Commands: - one --required + one --required [flags] A subcommand. - two --required --required-two --required-three + two --required --required-two --required-three [flags] Sub-sub-arg. - two four --required --required-two + two four --required --required-two [flags] Sub-sub-command. Run "test-app --help" for more information on a command. @@ -144,7 +144,7 @@ Run "test-app --help" for more information on a command. assert.NoError(t, err) }) assert.True(t, exited) - expected := `Usage: test-app two --required --required-two --required-three + expected := `Usage: test-app two --required --required-two --required-three [flags] Sub-sub-arg. @@ -215,18 +215,18 @@ func TestFlagsLast(t *testing.T) { assert.NoError(t, err) }) assert.True(t, exited) - expected := `Usage: test-app --required + expected := `Usage: test-app --required [flags] A test app. Commands: - one --required + one --required [flags] A subcommand. - two --required --required-two --required-three + two --required --required-two --required-three [flags] Sub-sub-arg. - two four --required --required-two + two four --required --required-two [flags] Sub-sub-command. Flags: @@ -253,7 +253,7 @@ Run "test-app --help" for more information on a command. assert.NoError(t, err) }) assert.True(t, exited) - expected := `Usage: test-app two --required --required-two --required-three + expected := `Usage: test-app two --required --required-two --required-three [flags] Sub-sub-arg. @@ -320,7 +320,7 @@ func TestHelpTree(t *testing.T) { assert.NoError(t, err) }) assert.True(t, exited) - expected := `Usage: test-app + expected := `Usage: test-app [flags] A test app. @@ -353,7 +353,7 @@ Run "test-app --help" for more information on a command. assert.NoError(t, err) }) assert.True(t, exited) - expected := `Usage: test-app one (un,uno) + expected := `Usage: test-app one (un,uno) [flags] subcommand one @@ -414,7 +414,7 @@ func TestHelpCompactNoExpand(t *testing.T) { assert.NoError(t, err) }) assert.True(t, exited) - expected := `Usage: test-app + expected := `Usage: test-app [flags] A test app. @@ -443,7 +443,7 @@ Run "test-app --help" for more information on a command. assert.NoError(t, err) }) assert.True(t, exited) - expected := `Usage: test-app one (un,uno) + expected := `Usage: test-app one (un,uno) [flags] subcommand one @@ -607,7 +607,7 @@ func TestAutoGroup(t *testing.T) { }), ) _, _ = app.Parse([]string{"--help", "two"}) - assert.Equal(t, `Usage: test two + assert.Equal(t, `Usage: test two [flags] A non grouped subcommand. @@ -691,7 +691,7 @@ func TestHelpGrouping(t *testing.T) { assert.True(t, exited) assert.NoError(t, err) }) - expected := `Usage: test-app + expected := `Usage: test-app [flags] A test app. @@ -710,26 +710,26 @@ Group B --grouped-b-string=STRING A string flag grouped in B. Commands: - two + two [flags] A non grouped subcommand. Group title taken from the kong.ExplicitGroups option A group header - one thing + one thing [flags] subcommand thing - one + one [flags] subcommand other - three + three [flags] Another subcommand grouped in A. Group B - one + one [flags] subcommand stuff - four + four [flags] Another subcommand grouped in B. Run "test-app --help" for more information on a command. @@ -747,7 +747,7 @@ Run "test-app --help" for more information on a command. assert.NoError(t, err) assert.True(t, exited) }) - expected := `Usage: test-app two + expected := `Usage: test-app two [flags] A non grouped subcommand. @@ -796,7 +796,7 @@ func TestUsageOnError(t *testing.T) { _, err := p.Parse([]string{}) p.FatalIfErrorf(err) - expected := `Usage: test --flag=STRING + expected := `Usage: test --flag=STRING [flags] Some description. @@ -824,7 +824,7 @@ func TestShortUsageOnError(t *testing.T) { assert.Error(t, err) p.FatalIfErrorf(err) - expected := `Usage: test --flag=STRING + expected := `Usage: test --flag=STRING [flags] Run "test --help" for more information. test: error: missing flags: --flag=STRING diff --git a/helpwrap1.19_test.go b/helpwrap1.19_test.go index 7b52f93..9034e59 100644 --- a/helpwrap1.19_test.go +++ b/helpwrap1.19_test.go @@ -32,7 +32,7 @@ func TestCustomWrap(t *testing.T) { _, err := app.Parse([]string{"--help"}) assert.NoError(t, err) - expected := `Usage: test-app + expected := `Usage: test-app [flags] A test app. diff --git a/kong_test.go b/kong_test.go index 3e71979..bd1ecfa 100644 --- a/kong_test.go +++ b/kong_test.go @@ -1576,7 +1576,7 @@ func TestPassthroughCmdOnlyArgs(t *testing.T) { } `cmd:"" passthrough:""` } _, err := kong.New(&cli) - assert.EqualError(t, err, ".Command: passthrough command command [ ...] must not have subcommands or flags") + assert.EqualError(t, err, ".Command: passthrough command command [ ...] [flags] must not have subcommands or flags") } func TestPassthroughCmdOnlyStringArgs(t *testing.T) { diff --git a/model.go b/model.go index 4e59fea..8d1f82f 100644 --- a/model.go +++ b/model.go @@ -162,6 +162,16 @@ func (n *Node) Summary() string { } else if len(n.Children) > 0 { summary += " " } + allFlags := n.Flags + if n.Parent != nil { + allFlags = append(allFlags, n.Parent.Flags...) + } + for _, flag := range allFlags { + if !flag.Required { + summary += " [flags]" + break + } + } return summary }