func (cmd *Command) GenMan(header *GenManHeader, out *bytes.Buffer) {
	if header == nil {
		header = &GenManHeader{}
	}
	buf := genMarkdown(cmd, header)
	final := mangen.Render(buf)
	out.Write(final)
}
GenMan will generate a man page for the given command in the out buffer.
The header argument may be nil, however obviously out may not.
package cobra
import (
	"bytes"
	"fmt"
	"os"
	"sort"
	"strings"
	"time"
	mangen "github.com/cpuguy83/go-md2man/md2man"
	"github.com/spf13/pflag"
)
func GenManTree(cmd *Command, header *GenManHeader, dir string) {
	cmd.GenManTree(header, dir)
}
func (cmd *Command) GenManTree(header *GenManHeader, dir string) {
	if header == nil {
		header = &GenManHeader{}
	}
	for _, c := range cmd.Commands() {
		if !c.IsAvailableCommand() || c == cmd.helpCommand {
			continue
		}
		GenManTree(c, header, dir)
	}
	out := new(bytes.Buffer)
	needToResetTitle := header.Title == ""
	cmd.GenMan(header, out)
	if needToResetTitle {
		header.Title = ""
	}
	filename := cmd.CommandPath()
	filename = dir + strings.Replace(filename, " ", "-", -1) + ".1"
	outFile, err := os.Create(filename)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	defer outFile.Close()
	_, err = outFile.Write(out.Bytes())
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
type GenManHeader struct {
	Title   string
	Section string
	Date    *time.Time
	date    string
	Source  string
	Manual  string
}
func GenMan(cmd *Command, header *GenManHeader, out *bytes.Buffer) {
	cmd.GenMan(header, out)
}