GenReSTTreeCustom is the same as GenReSTTree, but with custom filePrepender and linkHandler.
(cmd *cobra.Command, dir string, filePrepender func(string) string, linkHandler func(string, string) string)
| 143 | // GenReSTTreeCustom is the same as GenReSTTree, but |
| 144 | // with custom filePrepender and linkHandler. |
| 145 | func GenReSTTreeCustom(cmd *cobra.Command, dir string, filePrepender func(string) string, linkHandler func(string, string) string) error { |
| 146 | for _, c := range cmd.Commands() { |
| 147 | if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() { |
| 148 | continue |
| 149 | } |
| 150 | if err := GenReSTTreeCustom(c, dir, filePrepender, linkHandler); err != nil { |
| 151 | return err |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | basename := strings.ReplaceAll(cmd.CommandPath(), " ", "_") + ".rst" |
| 156 | filename := filepath.Join(dir, basename) |
| 157 | f, err := os.Create(filename) |
| 158 | if err != nil { |
| 159 | return err |
| 160 | } |
| 161 | defer f.Close() |
| 162 | |
| 163 | if _, err := io.WriteString(f, filePrepender(filename)); err != nil { |
| 164 | return err |
| 165 | } |
| 166 | if err := GenReSTCustom(cmd, f, linkHandler); err != nil { |
| 167 | return err |
| 168 | } |
| 169 | return nil |
| 170 | } |
| 171 | |
| 172 | // indentString adapted from: https://github.com/kr/text/blob/main/indent.go |
| 173 | func indentString(s, p string) string { |
no test coverage detected