Compare commits
2 Commits
517d4482c9
...
fe396b7537
| Author | SHA1 | Date | |
|---|---|---|---|
| fe396b7537 | |||
| 6eb04aa3c5 |
@@ -69,6 +69,7 @@ func printRunUsage() {
|
||||
func buildRootCommand(cfg *config.Config) *cli.Command {
|
||||
helpPrinterOnce.Do(func() {
|
||||
defaultHelpPrinter = cli.HelpPrinter
|
||||
})
|
||||
cli.HelpPrinter = func(w io.Writer, templ string, data interface{}) {
|
||||
if cmd, ok := data.(*cli.Command); ok && cmd.Root() == cmd {
|
||||
printRootUsage()
|
||||
@@ -76,7 +77,6 @@ func buildRootCommand(cfg *config.Config) *cli.Command {
|
||||
}
|
||||
defaultHelpPrinter(w, templ, data)
|
||||
}
|
||||
})
|
||||
|
||||
root := &cli.Command{
|
||||
Name: "goyco",
|
||||
@@ -94,6 +94,10 @@ func buildRootCommand(cfg *config.Config) *cli.Command {
|
||||
commands.SetJSONOutput(cmd.Bool("json"))
|
||||
return ctx, nil
|
||||
},
|
||||
After: func(ctx context.Context, cmd *cli.Command) error {
|
||||
cli.HelpPrinter = defaultHelpPrinter
|
||||
return nil
|
||||
},
|
||||
Action: func(_ context.Context, cmd *cli.Command) error {
|
||||
if cmd.NArg() == 0 {
|
||||
printRootUsage()
|
||||
|
||||
@@ -132,7 +132,7 @@ func TestPrintRunUsage(t *testing.T) {
|
||||
printRunUsage()
|
||||
}
|
||||
|
||||
func TestDispatchCommand(t *testing.T) {
|
||||
func TestRootCommandDispatch(t *testing.T) {
|
||||
t.Run("unknown command", func(t *testing.T) {
|
||||
cfg := testutils.NewTestConfig()
|
||||
cmd := buildRootCommand(cfg)
|
||||
|
||||
Reference in New Issue
Block a user