man_docs.md 469 字节
Newer Older
1 2
# Generating Man Pages For Your Own cobra.Command

3
Generating man pages from a cobra command is incredibly easy. An example is as follows:
4 5 6 7 8 9

```go
package main

import (
	"github.com/spf13/cobra"
10
	"github.com/spf13/cobra/doc"
11 12 13 14 15 16 17 18 19 20 21
)

func main() {
	cmd := &cobra.Command{
		Use:   "test",
		Short: "my test program",
	}
	header := &cobra.GenManHeader{
		Title: "MINE",
		Section: "3",
	}
22
	doc.GenManTree(cmd, header, "/tmp")
23 24 25 26
}
```

That will get you a man page `/tmp/test.1`