mirror of
https://github.com/packwiz/packwiz.git
synced 2025-10-14 06:54:32 +02:00
Add markdown command
This commit is contained in:
39
utils/markdown.go
Normal file
39
utils/markdown.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/cobra/doc"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// markdownCmd represents the markdown command
|
||||
var markdownCmd = &cobra.Command{
|
||||
Use: "markdown",
|
||||
Short: "Generate markdown documentation (that you might be reading right now!!)",
|
||||
Aliases: []string{"md"},
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
outDir := viper.GetString("utils.markdown.dir")
|
||||
err := os.MkdirAll(outDir, os.ModePerm)
|
||||
if err != nil {
|
||||
fmt.Printf("Error creating directory: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
err = doc.GenMarkdownTree(cmd.Root(), outDir)
|
||||
if err != nil {
|
||||
fmt.Printf("Error generating markdown: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println("Generated markdown successfully!")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
utilsCmd.AddCommand(markdownCmd)
|
||||
|
||||
markdownCmd.Flags().String("dir", ".", "The destination directory to save docs in")
|
||||
viper.BindPFlag("utils.markdown.dir", markdownCmd.Flags().Lookup("dir"))
|
||||
}
|
Reference in New Issue
Block a user