genManTreeFromOpts generates a man page for the command and all descendants. The pages are written to the opts.Path directory.
(cmd *cobra.Command, opts GenManTreeOptions)
| 39 | // genManTreeFromOpts generates a man page for the command and all descendants. |
| 40 | // The pages are written to the opts.Path directory. |
| 41 | func genManTreeFromOpts(cmd *cobra.Command, opts GenManTreeOptions) error { |
| 42 | for _, c := range cmd.Commands() { |
| 43 | if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() { |
| 44 | continue |
| 45 | } |
| 46 | if err := genManTreeFromOpts(c, opts); err != nil { |
| 47 | return err |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | section := "1" |
| 52 | separator := "_" |
| 53 | if opts.CommandSeparator != "" { |
| 54 | separator = opts.CommandSeparator |
| 55 | } |
| 56 | basename := strings.Replace(cmd.CommandPath(), " ", separator, -1) |
| 57 | filename := filepath.Join(opts.Path, basename+"."+section) |
| 58 | f, err := os.Create(filename) |
| 59 | if err != nil { |
| 60 | return err |
| 61 | } |
| 62 | defer f.Close() |
| 63 | |
| 64 | var versionString string |
| 65 | if v := os.Getenv("GH_VERSION"); v != "" { |
| 66 | versionString = "GitHub CLI " + v |
| 67 | } |
| 68 | |
| 69 | return renderMan(cmd, &GenManHeader{ |
| 70 | Section: section, |
| 71 | Source: versionString, |
| 72 | Manual: "GitHub CLI manual", |
| 73 | }, f) |
| 74 | } |
| 75 | |
| 76 | // GenManTreeOptions is the options for generating the man pages. |
| 77 | // Used only in GenManTreeFromOpts. |