forked from gotracker/gotracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.go
More file actions
59 lines (53 loc) · 1.52 KB
/
Copy pathdocs.go
File metadata and controls
59 lines (53 loc) · 1.52 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
package command
import (
"errors"
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)
var (
docsFormat string = "markdown"
docsValidFormats = []string{"markdown", "yaml", "manpage"}
docsOutputDir string = "./docs"
)
func init() {
if flags := docsCmd.Flags(); flags != nil {
flags.StringVarP(&docsFormat, "format", "f", docsFormat, fmt.Sprintf("desired format for generated documents {%s}", strings.Join(docsValidFormats, ", ")))
flags.StringVarP(&docsOutputDir, "output-dir", "o", docsOutputDir, "output directory for generated documents")
}
rootCmd.AddCommand(docsCmd)
}
var (
docsCmd = &cobra.Command{
Use: "docs",
Short: "Generate documentation for Gotracker",
Long: `Generate the documentation for Gotracker in one of many different formats.`,
RunE: func(cmd *cobra.Command, args []string) error {
switch docsFormat {
case "markdown", "md":
if err := os.MkdirAll(docsOutputDir, 0755); err != nil {
return err
}
return doc.GenMarkdownTree(rootCmd, docsOutputDir)
case "yaml", "yml":
if err := os.MkdirAll(docsOutputDir, 0755); err != nil {
return err
}
return doc.GenYamlTree(rootCmd, docsOutputDir)
case "manpage", "man":
if err := os.MkdirAll(docsOutputDir, 0755); err != nil {
return err
}
manHead := &doc.GenManHeader{
Title: "GOTRACKER",
Section: "3",
}
return doc.GenManTree(rootCmd, manHead, docsOutputDir)
default:
return errors.New("unsupported document format")
}
},
}
)