@@ -16,6 +16,8 @@ import (
1616)
1717
1818var fileName string
19+ var outputPath string
20+ var debug bool
1921var rootCmd = & cobra.Command {
2022 Use : "doc-gen" ,
2123 Short : "Generate the documentation for the sl plugin" ,
@@ -25,7 +27,10 @@ var rootCmd = &cobra.Command{
2527 },
2628}
2729
30+
2831func main () {
32+ rootCmd .Flags ().StringVarP (& outputPath , "output" , "o" , "./docs" , "Output path, default to ./docs ." )
33+ rootCmd .Flags ().BoolVarP (& debug , "verbose" , "v" , false , "Enable Debug logging." )
2934 err := rootCmd .Execute ()
3035 checkError (err )
3136 return
@@ -84,6 +89,7 @@ func CliDocs() {
8489 // This is a single command, like 'call-api' and doesn't have sub-commands
8590 thisCmdGroup .Commands = []SlCmdDoc {cobraToSl (iCmd , "" )}
8691 }
92+ printDebug (fmt .Sprintf ("Working on command group %s\n " , shortName ))
8793 PrintMakrdown (thisCmdGroup )
8894 CmdGroups = append (CmdGroups , thisCmdGroup )
8995 }
@@ -121,7 +127,8 @@ ibmcloud {{.Use}}
121127
122128 mdTemplate , err := template .New ("cmd template" ).Parse (cmdTemplate )
123129 checkError (err )
124- filename := fmt .Sprintf ("%v.md" , cmd .CommandShortLink )
130+ filename := fmt .Sprintf ("%s/%v.md" , outputPath , cmd .CommandShortLink )
131+ printDebug (fmt .Sprintf ("\t Creating file %s\n " , filename ))
125132 outfile , err := os .Create (filename ) //#nosec G304 -- This is a false positive
126133 defer outfile .Close ()
127134 err = mdTemplate .Execute (outfile , cmd )
@@ -201,3 +208,9 @@ func buildSlCmdFlag(topCommand *cobra.Command) []SlCmdFlag {
201208 })
202209 return flags
203210}
211+
212+ func printDebug (output string ) {
213+ if debug {
214+ fmt .Printf (output )
215+ }
216+ }
0 commit comments