Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions command_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func (cmd *Command) run(ctx context.Context, osArgs []string) (_ context.Context
var rargs Args = &stringSliceArgs{v: osArgs}
var args Args = &stringSliceArgs{rargs.Tail()}

if cmd.isCompletionCommand {
tracef("completion command detected, skipping pre-parse (cmd=%[1]q)", cmd.Name)
if cmd.isCompletionCommand || cmd.Name == helpName {
tracef("special command detected, skipping pre-parse (cmd=%[1]q)", cmd.Name)
cmd.parsedArgs = args
return ctx, cmd.Action(ctx, cmd)
}
Expand Down
2 changes: 1 addition & 1 deletion completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestCompletionEnable(t *testing.T) {
cmd := &Command{
EnableShellCompletion: true,
Flags: []Flag{
&BoolFlag{
&StringFlag{
Name: "goo",
Required: true,
},
Expand Down
30 changes: 29 additions & 1 deletion help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestShowSubcommandHelpAndExit(t *testing.T) {
require.Equal(t, 42, lastExitCode)
}

func Test_Help_RequiredFlagsNoDefault(t *testing.T) {
func Test_HelpFlag_RequiredFlagsNoDefault(t *testing.T) {
output := new(bytes.Buffer)

cmd := &Command{
Expand Down Expand Up @@ -136,6 +136,34 @@ GLOBAL OPTIONS:
"expected output to include usage text")
}

func Test_HelpCommand_RequiredFlagsNoDefault(t *testing.T) {
output := new(bytes.Buffer)

cmd := &Command{
Flags: []Flag{
&Int64Flag{Name: "foo", Aliases: []string{"f"}, Required: true},
},
Arguments: AnyArguments,
Writer: output,
}

_ = cmd.Run(buildTestContext(t), []string{"test", "help"})

expected := `NAME:
test - A new cli application

USAGE:
test [global options] [arguments...]

GLOBAL OPTIONS:
--foo int, -f int
--help, -h show help
`

assert.Contains(t, output.String(), expected,
"expected output to include usage text")
}

func Test_Help_Custom_Flags(t *testing.T) {
oldFlag := HelpFlag
defer func() {
Expand Down