add doc command

This commit is contained in:
Samuel Lorch 2021-09-09 09:19:33 +02:00
parent 03852b0bca
commit 08cb902aad
5 changed files with 112 additions and 2 deletions

34
cmd/doc.go Normal file
View file

@ -0,0 +1,34 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)
// configureCmd represents the configure command
var genDocCmd = &cobra.Command{
Use: "gendoc",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
docType, err := cmd.Flags().GetString("type")
if err != nil {
return err
}
cmd.DisableAutoGenTag = true
switch docType {
case "markdown":
return doc.GenMarkdownTree(rootCmd, "doc")
case "man":
return doc.GenManTree(rootCmd, nil, "man")
default:
return fmt.Errorf("Unknown type: %v", docType)
}
},
}
func init() {
rootCmd.AddCommand(genDocCmd)
genDocCmd.Flags().StringP("type", "t", "markdown", "what to generate, markdown or man")
}