Skip to content

Commit 653c378

Browse files
authored
set cmd.Action to default ShowCommandHelp when nil (#1308)
1 parent d954157 commit 653c378

3 files changed

Lines changed: 7 additions & 18 deletions

File tree

cmd/src/abc.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package main
22

33
import (
4-
"context"
5-
64
"github.com/sourcegraph/src-cli/internal/clicompat"
75
"github.com/urfave/cli/v3"
86
)
@@ -18,12 +16,6 @@ var abcCommand = clicompat.Wrap(&cli.Command{
1816
abcVariablesSetCommand,
1917
abcVariablesDeleteCommand,
2018
},
21-
Action: func(ctx context.Context, cmd *cli.Command) error {
22-
return cli.ShowSubcommandHelp(cmd)
23-
},
2419
}),
2520
},
26-
Action: func(ctx context.Context, cmd *cli.Command) error {
27-
return cli.ShowSubcommandHelp(cmd)
28-
},
2921
})

cmd/src/auth.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package main
22

33
import (
4-
"context"
5-
64
"github.com/sourcegraph/src-cli/internal/clicompat"
75
"github.com/urfave/cli/v3"
86
)
@@ -32,7 +30,4 @@ var authCommand = clicompat.Wrap(&cli.Command{
3230
Commands: []*cli.Command{
3331
authTokenCommand,
3432
},
35-
Action: func(ctx context.Context, cmd *cli.Command) error {
36-
return cli.ShowSubcommandHelp(cmd)
37-
},
3833
})

internal/clicompat/help.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ func Wrap(cmd *cli.Command) *cli.Command {
1616
}
1717

1818
cmd.OnUsageError = OnUsageError
19-
cmd.Action = wrapWithHelpOnUsageError(cmd.Action)
19+
if cmd.Action == nil {
20+
cmd.Action = func(ctx context.Context, cmd *cli.Command) error {
21+
return cli.ShowSubcommandHelp(cmd)
22+
}
23+
} else {
24+
cmd.Action = wrapWithHelpOnUsageError(cmd.Action)
25+
}
2026
return cmd
2127
}
2228

2329
func wrapWithHelpOnUsageError(action cli.ActionFunc) cli.ActionFunc {
24-
if action == nil {
25-
return nil
26-
}
27-
2830
return func(ctx context.Context, cmd *cli.Command) error {
2931
err := action(ctx, cmd)
3032
if err != nil && errors.HasType[*cmderrors.UsageError](err) {

0 commit comments

Comments
 (0)