wrapHelp wraps a custom TUI help renderer so that --json produces structured JSON and non-TTY output falls back to Cobra's default plain-text help.
(render func(cmd *cobra.Command))
| 11 | // wrapHelp wraps a custom TUI help renderer so that --json produces structured |
| 12 | // JSON and non-TTY output falls back to Cobra's default plain-text help. |
| 13 | func wrapHelp(render func(cmd *cobra.Command)) func(*cobra.Command, []string) { |
| 14 | return func(cmd *cobra.Command, args []string) { |
| 15 | if JSONOutput { |
| 16 | printJSONHelp(cmd) |
| 17 | return |
| 18 | } |
| 19 | if !termx.IsTerminal(os.Stdout.Fd()) { |
| 20 | printDefaultHelp(cmd) |
| 21 | return |
| 22 | } |
| 23 | render(cmd) |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | type jsonFlag struct { |
| 28 | Name string `json:"name"` |