-
Notifications
You must be signed in to change notification settings - Fork 0
/
docs.go
43 lines (38 loc) · 857 Bytes
/
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
/*
*/
package cmd
import (
"fmt"
"io"
"os"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)
// docsCmd represents the docs command
var docsCmd = &cobra.Command{
Use: "docs",
Short: "Generate documentation for the command",
RunE: func(cmd *cobra.Command, args []string) error {
dir, err := cmd.Flags().GetString("dir")
if err != nil {
return err
}
if dir == "" {
if dir, err = os.MkdirTemp("", "move"); err != nil {
return err
}
}
return docsAction(os.Stdout, dir)
},
}
func init() {
RootCmd.AddCommand(docsCmd)
docsCmd.Flags().StringP("dir", "d", "", "Destination directory for docs")
}
func docsAction(out io.Writer, dir string) error {
if err := doc.GenMarkdownTree(RootCmd, dir); err != nil {
return err
}
_, err := fmt.Fprintf(out, "Documentation successfully created in %s\n", dir)
return err
}