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

Function GenManTreeFromOpts

doc/man_docs.go:48–80  ·  view source on GitHub ↗

GenManTreeFromOpts generates a man page for the command and all descendants. The pages are written to the opts.Path directory.

(cmd *cobra.Command, opts GenManTreeOptions)

Source from the content-addressed store, hash-verified

46// GenManTreeFromOpts generates a man page for the command and all descendants.
47// The pages are written to the opts.Path directory.
48func GenManTreeFromOpts(cmd *cobra.Command, opts GenManTreeOptions) error {
49 header := opts.Header
50 if header == nil {
51 header = &GenManHeader{}
52 }
53 for _, c := range cmd.Commands() {
54 if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
55 continue
56 }
57 if err := GenManTreeFromOpts(c, opts); err != nil {
58 return err
59 }
60 }
61 section := "1"
62 if header.Section != "" {
63 section = header.Section
64 }
65
66 separator := "_"
67 if opts.CommandSeparator != "" {
68 separator = opts.CommandSeparator
69 }
70 basename := strings.ReplaceAll(cmd.CommandPath(), " ", separator)
71 filename := filepath.Join(opts.Path, basename+"."+section)
72 f, err := os.Create(filename)
73 if err != nil {
74 return err
75 }
76 defer f.Close()
77
78 headerCopy := *header
79 return GenMan(cmd, &headerCopy, f)
80}
81
82// GenManTreeOptions is the options for generating the man pages.
83// Used only in GenManTreeFromOpts.

Callers 1

GenManTreeFunction · 0.85

Calls 5

GenManFunction · 0.85
CommandsMethod · 0.80
IsAvailableCommandMethod · 0.80
CommandPathMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…