github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/man/generate.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/docker/docker/cli/command" 8 "github.com/docker/docker/cli/command/commands" 9 "github.com/docker/docker/pkg/term" 10 "github.com/spf13/cobra" 11 "github.com/spf13/cobra/doc" 12 ) 13 14 func generateManPages(path string) error { 15 header := &doc.GenManHeader{ 16 Title: "DOCKER", 17 Section: "1", 18 Source: "Docker Community", 19 } 20 21 stdin, stdout, stderr := term.StdStreams() 22 dockerCli := command.NewDockerCli(stdin, stdout, stderr) 23 cmd := &cobra.Command{Use: "docker"} 24 commands.AddCommands(cmd, dockerCli) 25 26 cmd.DisableAutoGenTag = true 27 return doc.GenManTreeFromOpts(cmd, doc.GenManTreeOptions{ 28 Header: header, 29 Path: path, 30 CommandSeparator: "-", 31 }) 32 } 33 34 func main() { 35 path := "/tmp" 36 if len(os.Args) > 1 { 37 path = os.Args[1] 38 } 39 fmt.Printf("Generating man pages into %s\n", path) 40 if err := generateManPages(path); err != nil { 41 fmt.Fprintf(os.Stderr, "Failed to generate man pages: %s\n", err.Error()) 42 } 43 }