Debian Codegraph @

site/content/docgen/man.md

raw
1 # Generating Man Pages For Your Own cobra.Command
2
3 Generating man pages from a cobra command is incredibly easy. An example is as follows:
4
5 ```go
6 package main
7
8 import (
9 "log"
10
11 "github.com/spf13/cobra"
12 "github.com/spf13/cobra/doc"
13 )
14
15 func main() {
16 cmd := &cobra.Command{
17 Use: "test",
18 Short: "my test program",
19 }
20 header := &doc.GenManHeader{
21 Title: "MINE",
22 Section: "3",
23 }
24 err := doc.GenManTree(cmd, header, "/tmp")
25 if err != nil {
26 log.Fatal(err)
27 }
28 }
29 ```
30
31 That will get you a man page `/tmp/test.3`