MCPcopy
hub / github.com/cli/cli / genMarkdownCustom

Function genMarkdownCustom

internal/docs/markdown.go:133–176  ·  view source on GitHub ↗

genMarkdownCustom creates custom markdown output.

(cmd *cobra.Command, w io.Writer, linkHandler func(string) string)

Source from the content-addressed store, hash-verified

131
132// genMarkdownCustom creates custom markdown output.
133func genMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error {
134 fmt.Fprint(w, "{% raw %}")
135 fmt.Fprintf(w, "## %s\n\n", cmd.CommandPath())
136
137 hasLong := cmd.Long != ""
138 if !hasLong {
139 fmt.Fprintf(w, "%s\n\n", cmd.Short)
140 }
141 if cmd.Runnable() {
142 fmt.Fprintf(w, "```\n%s\n```\n\n", cmd.UseLine())
143 }
144 if hasLong {
145 fmt.Fprintf(w, "%s\n\n", cmd.Long)
146 }
147
148 for _, g := range root.GroupedCommands(cmd) {
149 fmt.Fprintf(w, "### %s\n\n", g.Title)
150 for _, subcmd := range g.Commands {
151 fmt.Fprintf(w, "* [%s](%s)\n", subcmd.CommandPath(), linkHandler(cmdManualPath(subcmd)))
152 }
153 fmt.Fprint(w, "\n\n")
154 }
155
156 if err := printOptions(w, cmd); err != nil {
157 return err
158 }
159 printAliases(w, cmd)
160 printJSONFields(w, cmd)
161 fmt.Fprint(w, "{% endraw %}\n")
162
163 if len(cmd.Example) > 0 {
164 fmt.Fprint(w, "### Examples\n\n{% highlight bash %}{% raw %}\n")
165 fmt.Fprint(w, cmd.Example)
166 fmt.Fprint(w, "{% endraw %}{% endhighlight %}\n\n")
167 }
168
169 if cmd.HasParent() {
170 p := cmd.Parent()
171 fmt.Fprint(w, "### See also\n\n")
172 fmt.Fprintf(w, "* [%s](%s)\n", p.CommandPath(), linkHandler(cmdManualPath(p)))
173 }
174
175 return nil
176}
177
178// GenMarkdownTreeCustom is the same as GenMarkdownTree, but
179// with custom filePrepender and linkHandler.

Callers 7

GenMarkdownTreeCustomFunction · 0.85
TestGenMdDocFunction · 0.85
TestGenMdNoHiddenParentsFunction · 0.85
TestGenMdAliasesFunction · 0.85
TestGenMdJSONFieldsFunction · 0.85

Calls 6

GroupedCommandsFunction · 0.92
linkHandlerFunction · 0.85
cmdManualPathFunction · 0.85
printOptionsFunction · 0.85
printAliasesFunction · 0.85
printJSONFieldsFunction · 0.85

Tested by 6

TestGenMdDocFunction · 0.68
TestGenMdNoHiddenParentsFunction · 0.68
TestGenMdAliasesFunction · 0.68
TestGenMdJSONFieldsFunction · 0.68