EmitJSON walks the command tree below `target`, builds a cmdhelp v0.1 Document, and writes it to w as indented JSON terminated by a newline. `root` MUST be the root cobra command (used to derive global flags and command-path keys relative to the binary). `target` is where the user requested help; p
(target, root *cobra.Command, opts Options, w io.Writer)
| 71 | // command-path keys relative to the binary). `target` is where the user |
| 72 | // requested help; pass root for both when the user runs `<cmd> help`. |
| 73 | func EmitJSON(target, root *cobra.Command, opts Options, w io.Writer) error { |
| 74 | doc := Build(target, root, opts) |
| 75 | enc := json.NewEncoder(w) |
| 76 | enc.SetIndent("", " ") |
| 77 | return enc.Encode(doc) |
| 78 | } |
| 79 | |
| 80 | // Build returns a cmdhelp Document without serializing it. Callers that |
| 81 | // need to inspect or further mutate the document (tests, dynamic enum |