-
Notifications
You must be signed in to change notification settings - Fork 132
/
docs.go
46 lines (39 loc) · 1.1 KB
/
docs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)
var docsPath string
// docsCmd returns the generate command that, when run, generates
// documentation.
func docsCmd(name string) *cobra.Command {
cmd := &cobra.Command{
Use: "docs [markdown|man]",
Short: "Generate documentation",
Hidden: true,
ValidArgs: []string{"markdown", "man"},
Args: cobra.ExactValidArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
format := args[0]
switch format {
case "markdown":
return doc.GenMarkdownTree(cmd.Parent(), docsPath)
case "man":
header := &doc.GenManHeader{Title: name}
return doc.GenManTree(cmd.Parent(), header, docsPath)
}
// ValidArgs make this error response dead-code
return fmt.Errorf("unknown format: %q", format)
},
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
},
}
cmd.Flags().StringVarP(&docsPath, "path", "p", "", "Path where documentation will be generated")
return cmd
}
func init() {
docsCmd := docsCmd(rootCmd.CalledAs())
rootCmd.AddCommand(docsCmd)
}