Skip to content

Commit 30c4df2

Browse files
authored
Merge pull request urfave#2000 from dearchap/issue_1921_fix
Fix:(issue_1921) Dont display [command] in help
2 parents 7ec374f + 68f9c2c commit 30c4df2

File tree

7 files changed

+14
-37
lines changed

7 files changed

+14
-37
lines changed

command.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,9 +900,10 @@ func (cmd *Command) VisibleCategories() []CommandCategory {
900900
func (cmd *Command) VisibleCommands() []*Command {
901901
var ret []*Command
902902
for _, command := range cmd.Commands {
903-
if !command.Hidden {
904-
ret = append(ret, command)
903+
if command.Hidden || command.Name == helpName {
904+
continue
905905
}
906+
ret = append(ret, command)
906907
}
907908
return ret
908909
}

command_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,6 @@ func TestCommand_VisibleCommands(t *testing.T) {
10261026
cmd.setupDefaults([]string{"cli.test"})
10271027
expected := []*Command{
10281028
cmd.Commands[0],
1029-
cmd.Commands[2], // help
10301029
}
10311030
actual := cmd.VisibleCommands()
10321031
assert.Len(t, actual, len(expected))

docs/migrate-v2-to-v3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ in addition to other specific args. This allows handler functions to utilize con
123123
blocking/time-specific operations and so on
124124

125125
* OLD: `type BeforeFunc func(*Context) error`
126-
* NEW: `type BeforeFunc func(context.Context, *cli.Command) error`
126+
* NEW: `type BeforeFunc func(context.Context, *cli.Command) (context.Context, error)`
127127

128128
* OLD: `type AfterFunc func(*Context) error`
129129
* NEW: `type AfterFunc func(context.Context, *cli.Command) error`

docs/v3/examples/flags.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,9 @@ getting data from a yaml file below.
501501

502502
```go
503503
// --- >8 ---
504-
command.Before = altsrc.InitInputSourceWithContext(command.Flags, NewYamlSourceFromFlagFunc("load"))
504+
command.Before = func(ctx context.Context, cmd *Command) (context.Context, error) {
505+
return ctx, altsrc.InitInputSourceWithContext(command.Flags, NewYamlSourceFromFlagFunc("load"))
506+
}
505507
```
506508

507509
The code above will use the "load" string as a flag name to get the file name of

docs/v3/examples/full-api-example.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ func main() {
153153
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
154154
fmt.Fprintf(cmd.Root().Writer, "lipstick\nkiss\nme\nlipstick\nringo\n")
155155
},
156-
Before: func(ctx context.Context, cmd *cli.Command) error {
156+
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
157157
fmt.Fprintf(cmd.Root().Writer, "HEEEERE GOES\n")
158-
return nil
158+
return nil, nil
159159
},
160160
After: func(ctx context.Context, cmd *cli.Command) error {
161161
fmt.Fprintf(cmd.Root().Writer, "Phew!\n")

examples_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,11 @@ func ExampleCommand_Run_commandHelp() {
181181
// greet describeit - use it to see a description
182182
//
183183
// USAGE:
184-
// greet describeit [command [command options]] [arguments...]
184+
// greet describeit [arguments...]
185185
//
186186
// DESCRIPTION:
187187
// This is how we describe describeit the function
188188
//
189-
// COMMANDS:
190-
// help, h Shows a list of commands or help for one command
191-
//
192189
// OPTIONS:
193190
// --help, -h show help
194191
}
@@ -205,10 +202,7 @@ func ExampleCommand_Run_noAction() {
205202
// greet - A new cli application
206203
//
207204
// USAGE:
208-
// greet [global options] [command [command options]] [arguments...]
209-
//
210-
// COMMANDS:
211-
// help, h Shows a list of commands or help for one command
205+
// greet [global options] [arguments...]
212206
//
213207
// GLOBAL OPTIONS:
214208
// --help, -h show help

help_test.go

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,7 @@ func Test_Help_RequiredFlagsNoDefault(t *testing.T) {
8282
test - A new cli application
8383
8484
USAGE:
85-
test [global options] [command [command options]] [arguments...]
86-
87-
COMMANDS:
88-
help, h Shows a list of commands or help for one command
85+
test [global options] [arguments...]
8986
9087
GLOBAL OPTIONS:
9188
--foo value, -f value
@@ -198,7 +195,7 @@ func Test_helpCommand_InHelpOutput(t *testing.T) {
198195
s := output.String()
199196

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

204201
func TestHelpCommand_FullName(t *testing.T) {
@@ -361,7 +358,6 @@ func TestShowCommandHelp_AppendHelp(t *testing.T) {
361358
args: []string{"app", "cmd", "help"},
362359
verify: func(t *testing.T, outString string) {
363360
r := require.New(t)
364-
r.Contains(outString, "help, h Shows a list of commands or help for one command")
365361
r.Contains(outString, "--help, -h show help")
366362
},
367363
},
@@ -1512,11 +1508,6 @@ DESCRIPTION:
15121508
enough to wrap in this test
15131509
case
15141510
1515-
COMMANDS:
1516-
help, h Shows a list of
1517-
commands or help
1518-
for one command
1519-
15201511
OPTIONS:
15211512
--help, -h show help
15221513
`,
@@ -1655,11 +1646,6 @@ USAGE:
16551646
this is long enough to wrap
16561647
even more
16571648
1658-
COMMANDS:
1659-
help, h Shows a list of
1660-
commands or help
1661-
for one command
1662-
16631649
OPTIONS:
16641650
--test-f value my test
16651651
usage
@@ -1733,12 +1719,7 @@ func TestCategorizedHelp(t *testing.T) {
17331719
application
17341720
17351721
USAGE:
1736-
cli.test [global options] [command [command options]] [arguments...]
1737-
1738-
COMMANDS:
1739-
help, h Shows a list of
1740-
commands or help
1741-
for one command
1722+
cli.test [global options] [arguments...]
17421723
17431724
GLOBAL OPTIONS:
17441725
--help, -h show help

0 commit comments

Comments
 (0)