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

Function genMan

doc/man_docs.go:202–246  ·  view source on GitHub ↗
(cmd *cobra.Command, header *GenManHeader)

Source from the content-addressed store, hash-verified

200}
201
202func genMan(cmd *cobra.Command, header *GenManHeader) []byte {
203 cmd.InitDefaultHelpCmd()
204 cmd.InitDefaultHelpFlag()
205
206 // something like `rootcmd-subcmd1-subcmd2`
207 dashCommandName := strings.ReplaceAll(cmd.CommandPath(), " ", "-")
208
209 buf := new(bytes.Buffer)
210
211 manPreamble(buf, header, cmd, dashCommandName)
212 manPrintOptions(buf, cmd)
213 if len(cmd.Example) > 0 {
214 buf.WriteString("# EXAMPLE\n")
215 fmt.Fprintf(buf, "```\n%s\n```\n", cmd.Example)
216 }
217 if hasSeeAlso(cmd) {
218 buf.WriteString("# SEE ALSO\n")
219 seealsos := make([]string, 0)
220 if cmd.HasParent() {
221 parentPath := cmd.Parent().CommandPath()
222 dashParentPath := strings.ReplaceAll(parentPath, " ", "-")
223 seealso := fmt.Sprintf("**%s(%s)**", dashParentPath, header.Section)
224 seealsos = append(seealsos, seealso)
225 cmd.VisitParents(func(c *cobra.Command) {
226 if c.DisableAutoGenTag {
227 cmd.DisableAutoGenTag = c.DisableAutoGenTag
228 }
229 })
230 }
231 children := cmd.Commands()
232 sort.Sort(byName(children))
233 for _, c := range children {
234 if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
235 continue
236 }
237 seealso := fmt.Sprintf("**%s-%s(%s)**", dashCommandName, c.Name(), header.Section)
238 seealsos = append(seealsos, seealso)
239 }
240 buf.WriteString(strings.Join(seealsos, ", ") + "\n")
241 }
242 if !cmd.DisableAutoGenTag {
243 fmt.Fprintf(buf, "# HISTORY\n%s Auto generated by spf13/cobra\n", header.Date.Format("2-Jan-2006"))
244 }
245 return buf.Bytes()
246}

Callers 1

GenManFunction · 0.85

Calls 14

manPreambleFunction · 0.85
manPrintOptionsFunction · 0.85
hasSeeAlsoFunction · 0.85
byNameTypeAlias · 0.85
InitDefaultHelpCmdMethod · 0.80
InitDefaultHelpFlagMethod · 0.80
CommandPathMethod · 0.80
HasParentMethod · 0.80
ParentMethod · 0.80
VisitParentsMethod · 0.80
CommandsMethod · 0.80
IsAvailableCommandMethod · 0.80

Tested by

no test coverage detected