forked from AliyunContainerService/pouch
/
generate_doc.go
54 lines (46 loc) · 1.2 KB
/
generate_doc.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
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)
// genDocDescription is used to describe gen-doc command in detail and auto generate command doc.
// TODO: add description
var genDocDescription = ""
// GenDocCommand is used to implement 'exec' command.
type GenDocCommand struct {
baseCommand
}
// Init initializes ExecCommand command.
func (g *GenDocCommand) Init(c *Cli) {
g.cli = c
g.cmd = &cobra.Command{
Use: "gen-doc",
Short: "Generate docs",
Long: genDocDescription,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return g.runGenDoc(args)
},
Example: genDocExample(),
}
g.addFlags()
}
// addFlags adds flags for specific command.
func (g *GenDocCommand) addFlags() {
}
func (g *GenDocCommand) runGenDoc(args []string) error {
if _, err := os.Stat("./docs/commandline"); err != nil {
if os.IsNotExist(err) {
return fmt.Errorf("directory docs/commandline does not exist")
}
return err
}
return doc.GenMarkdownTree(g.cli.rootCmd, "./docs/commandline")
}
// genDocExample shows examples in genDoc command, and is used in auto-generated cli docs.
// TODO: add example
func genDocExample() string {
return ""
}