Skip to content

Commit

Permalink
add custom help command
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Nov 26, 2024
1 parent bd145e2 commit e0506ed
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Version:
rootCmd.PersistentFlags().Bool("no-audit", try.Try(try.EnvBool("RELAY_NO_AUDIT"), try.Static(false)), "disable audit logs [$RELAY_NO_AUDIT=1]")
rootCmd.PersistentFlags().BoolVar(&cfg.Logger.DisableColor, "no-color", false, "disable colors in command output [$NO_COLOR=1]")

rootCmd.SetHelpCommand(cmd.HelpCmd())
rootCmd.AddCommand(cmd.AddCmd(manager))
rootCmd.AddCommand(cmd.DelCmd(manager))
rootCmd.AddCommand(cmd.LsCmd(manager))
Expand Down
32 changes: 32 additions & 0 deletions internal/cmd/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

func HelpCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "help [command]",
Short: "help for a command",
SilenceUsage: true,
RunE: func(c *cobra.Command, args []string) error {
cmd, _, e := c.Root().Find(args)

if cmd == nil || e != nil {
fmt.Printf("warning: unknown help topic %#q\n", args)

return e
}

if err := cmd.Help(); err != nil {
return err
}

return nil
},
}

return cmd
}

0 comments on commit e0506ed

Please sign in to comment.