Skip to content

Commit

Permalink
Fix:(issue_1921) Dont display [command] in help
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap committed Nov 1, 2024
1 parent 7ec374f commit 2075bc5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
5 changes: 3 additions & 2 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,9 +900,10 @@ func (cmd *Command) VisibleCategories() []CommandCategory {
func (cmd *Command) VisibleCommands() []*Command {
var ret []*Command
for _, command := range cmd.Commands {
if !command.Hidden {
ret = append(ret, command)
if command.Hidden || command.Name == helpName {
continue
}
ret = append(ret, command)
}
return ret
}
Expand Down
1 change: 0 additions & 1 deletion command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,6 @@ func TestCommand_VisibleCommands(t *testing.T) {
cmd.setupDefaults([]string{"cli.test"})
expected := []*Command{
cmd.Commands[0],
cmd.Commands[2], // help
}
actual := cmd.VisibleCommands()
assert.Len(t, actual, len(expected))
Expand Down
10 changes: 2 additions & 8 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,11 @@ func ExampleCommand_Run_commandHelp() {
// greet describeit - use it to see a description
//
// USAGE:
// greet describeit [command [command options]] [arguments...]
// greet describeit [arguments...]
//
// DESCRIPTION:
// This is how we describe describeit the function
//
// COMMANDS:
// help, h Shows a list of commands or help for one command
//
// OPTIONS:
// --help, -h show help
}
Expand All @@ -205,10 +202,7 @@ func ExampleCommand_Run_noAction() {
// greet - A new cli application
//
// USAGE:
// greet [global options] [command [command options]] [arguments...]
//
// COMMANDS:
// help, h Shows a list of commands or help for one command
// greet [global options] [arguments...]
//
// GLOBAL OPTIONS:
// --help, -h show help
Expand Down
7 changes: 2 additions & 5 deletions help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ func Test_Help_RequiredFlagsNoDefault(t *testing.T) {
test - A new cli application
USAGE:
test [global options] [command [command options]] [arguments...]
COMMANDS:
help, h Shows a list of commands or help for one command
test [global options] [arguments...]
GLOBAL OPTIONS:
--foo value, -f value
Expand Down Expand Up @@ -198,7 +195,7 @@ func Test_helpCommand_InHelpOutput(t *testing.T) {
s := output.String()

require.NotContains(t, s, "\nCOMMANDS:\nGLOBAL OPTIONS:\n", "empty COMMANDS section detected")
require.Contains(t, s, "help, h", "missing \"help, h\"")
require.Contains(t, s, "--help, -h", "missing \"--help, --h\"")
}

func TestHelpCommand_FullName(t *testing.T) {
Expand Down

0 comments on commit 2075bc5

Please sign in to comment.