MCPcopy
hub / github.com/cli/cli / genMan

Function genMan

internal/docs/man.go:210–239  ·  view source on GitHub ↗
(cmd *cobra.Command, header *GenManHeader)

Source from the content-addressed store, hash-verified

208}
209
210func genMan(cmd *cobra.Command, header *GenManHeader) []byte {
211 cmd.InitDefaultHelpCmd()
212 cmd.InitDefaultHelpFlag()
213
214 // something like `rootcmd-subcmd1-subcmd2`
215 dashCommandName := strings.Replace(cmd.CommandPath(), " ", "-", -1)
216
217 buf := new(bytes.Buffer)
218
219 manPreamble(buf, header, cmd, dashCommandName)
220 for _, g := range root.GroupedCommands(cmd) {
221 fmt.Fprintf(buf, "# %s\n", strings.ToUpper(g.Title))
222 for _, subcmd := range g.Commands {
223 fmt.Fprintf(buf, "`%s`\n: %s\n\n", manLink(subcmd), subcmd.Short)
224 }
225 }
226 manPrintOptions(buf, cmd)
227 manPrintAliases(buf, cmd)
228 manPrintJSONFields(buf, cmd)
229 manPrintExitCodes(buf)
230 if len(cmd.Example) > 0 {
231 buf.WriteString("# EXAMPLE\n")
232 buf.WriteString(fmt.Sprintf("```\n%s\n```\n", cmd.Example))
233 }
234 if cmd.HasParent() {
235 buf.WriteString("# SEE ALSO\n")
236 buf.WriteString(fmt.Sprintf("`%s`\n", manLink(cmd.Parent())))
237 }
238 return buf.Bytes()
239}
240
241func manLink(cmd *cobra.Command) string {
242 p := cmd.CommandPath()

Callers 1

renderManFunction · 0.85

Calls 8

GroupedCommandsFunction · 0.92
manPreambleFunction · 0.85
manLinkFunction · 0.85
manPrintOptionsFunction · 0.85
manPrintAliasesFunction · 0.85
manPrintJSONFieldsFunction · 0.85
manPrintExitCodesFunction · 0.85
ReplaceMethod · 0.80

Tested by

no test coverage detected