File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ package cmd
2+
3+ import (
4+ "os"
5+
6+ "github.com/spf13/cobra"
7+ "github.com/spf13/cobra/doc"
8+ )
9+
10+ const (
11+ flagMkDirs = "mk-dirs"
12+ )
13+
14+ var metaDocsCmd = & cobra.Command {
15+ Use : "docs [dir]" ,
16+ Short : "Generate documentation to a directory" ,
17+ Args : cobra .ExactArgs (1 ),
18+ RunE : func (cmd * cobra.Command , args []string ) error {
19+ targetPath := args [0 ]
20+
21+ shouldMkDirs , err := cmd .Flags ().GetBool (flagMkDirs )
22+ if err != nil {
23+ return err
24+ }
25+ if shouldMkDirs {
26+ if err := mkDirs (targetPath ); err != nil {
27+ return err
28+ }
29+ }
30+
31+ rootCmd .DisableAutoGenTag = true
32+
33+ err = doc .GenMarkdownTree (rootCmd , targetPath )
34+ if err != nil {
35+ return err
36+ }
37+
38+ return nil
39+ },
40+ }
41+
42+ func mkDirs (dir string ) error {
43+ if err := os .MkdirAll (dir , os .ModePerm ); err != nil {
44+ return err
45+ }
46+
47+ return nil
48+ }
49+
50+ func init () {
51+ metaCmd .AddCommand (metaDocsCmd )
52+ metaDocsCmd .Flags ().Bool (flagMkDirs , false , "create directories if they do not exist" )
53+ }
Original file line number Diff line number Diff line change 1+ package cmd
2+
3+ import (
4+ "github.com/spf13/cobra"
5+ )
6+
7+ var metaCmd = & cobra.Command {
8+ Use : "meta" ,
9+ Short : "Meta commands for the tool" ,
10+ }
11+
12+ func init () {
13+ rootCmd .AddCommand (metaCmd )
14+ }
You can’t perform that action at this time.
0 commit comments