customHelpFunc returns a help function that renders styled help for all commands: agent JSON when --agent is set, curated categories for root, and a consistent styled layout for every subcommand.
(defaultHelp func(*cobra.Command, []string))
| 38 | // commands: agent JSON when --agent is set, curated categories for root, |
| 39 | // and a consistent styled layout for every subcommand. |
| 40 | func customHelpFunc(defaultHelp func(*cobra.Command, []string)) func(*cobra.Command, []string) { |
| 41 | return func(cmd *cobra.Command, args []string) { |
| 42 | if agentFlag { |
| 43 | printAgentHelp(cmd) |
| 44 | return |
| 45 | } |
| 46 | if cmd == cmd.Root() { |
| 47 | renderRootHelp(cmd.OutOrStdout(), cmd) |
| 48 | return |
| 49 | } |
| 50 | renderCommandHelp(cmd) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | func renderRootHelp(w io.Writer, cmd *cobra.Command) { |
| 55 | var b strings.Builder |
no test coverage detected