MCPcopy
hub / github.com/spf13/cobra / GenReSTTreeCustom

Function GenReSTTreeCustom

doc/rest_docs.go:145–170  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

143// GenReSTTreeCustom is the same as GenReSTTree, but
144// with custom filePrepender and linkHandler.
145func 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
173func indentString(s, p string) string {

Callers 1

GenReSTTreeFunction · 0.85

Calls 5

GenReSTCustomFunction · 0.85
CommandsMethod · 0.80
IsAvailableCommandMethod · 0.80
CommandPathMethod · 0.80

Tested by

no test coverage detected