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)
| 46 | // GenManTreeFromOpts generates a man page for the command and all descendants. |
| 47 | // The pages are written to the opts.Path directory. |
| 48 | func GenManTreeFromOpts(cmd *cobra.Command, opts GenManTreeOptions) error { |
| 49 | header := opts.Header |
| 50 | if header == nil { |
| 51 | header = &GenManHeader{} |
| 52 | } |
| 53 | for _, c := range cmd.Commands() { |
| 54 | if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() { |
| 55 | continue |
| 56 | } |
| 57 | if err := GenManTreeFromOpts(c, opts); err != nil { |
| 58 | return err |
| 59 | } |
| 60 | } |
| 61 | section := "1" |
| 62 | if header.Section != "" { |
| 63 | section = header.Section |
| 64 | } |
| 65 | |
| 66 | separator := "_" |
| 67 | if opts.CommandSeparator != "" { |
| 68 | separator = opts.CommandSeparator |
| 69 | } |
| 70 | basename := strings.ReplaceAll(cmd.CommandPath(), " ", separator) |
| 71 | filename := filepath.Join(opts.Path, basename+"."+section) |
| 72 | f, err := os.Create(filename) |
| 73 | if err != nil { |
| 74 | return err |
| 75 | } |
| 76 | defer f.Close() |
| 77 | |
| 78 | headerCopy := *header |
| 79 | return GenMan(cmd, &headerCopy, f) |
| 80 | } |
| 81 | |
| 82 | // GenManTreeOptions is the options for generating the man pages. |
| 83 | // Used only in GenManTreeFromOpts. |
no test coverage detected
searching dependent graphs…