Generating Man Pages For Your Own cobra.Command

Generating man pages from a cobra command is incredibly easy. An example is as follows:

  1. package main
  2. import (
  3. "log"
  4. "github.com/spf13/cobra"
  5. "github.com/spf13/cobra/doc"
  6. )
  7. func main() {
  8. cmd := &cobra.Command{
  9. Use: "test",
  10. Short: "my test program",
  11. }
  12. header := &doc.GenManHeader{
  13. Title: "MINE",
  14. Section: "3",
  15. }
  16. err := doc.GenManTree(cmd, header, "/tmp")
  17. if err != nil {
  18. log.Fatal(err)
  19. }
  20. }

That will get you a man page /tmp/test.3