Skip to content

Commit bd5a0eb

Browse files
Updating the docs builder, still a work in progress
1 parent 79767e4 commit bd5a0eb

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

docs/main.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,82 @@ import (
44
"fmt"
55
"os"
66
"strings"
7+
"sort"
78
"io/ioutil"
89
"path/filepath"
910
// "sort"
1011
"github.com/spf13/cobra/doc"
12+
"github.com/spf13/cobra"
1113
// "github.com/IBM-Cloud/ibm-cloud-cli-sdk/plugin"
1214
sl_plugin "github.ibm.com/SoftLayer/softlayer-cli/plugin"
1315
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal"
1416
"github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers"
1517
"github.com/softlayer/softlayer-go/session"
1618
)
1719

20+
var fileName string
21+
var rootCmd = &cobra.Command{
22+
Use: "doc-gen",
23+
Short: "Generate the documentation for the sl plugin",
24+
RunE: func(Cmd *cobra.Command, args []string) error {
25+
CliDocs()
26+
return nil
27+
},
28+
}
1829

1930
func main() {
31+
err := rootCmd.Execute()
32+
if err != nil {
33+
fmt.Printf(err.Error())
34+
}
35+
return
36+
}
37+
38+
// This function builds the documentation for IBMCLOUD docs
39+
func CliDocs() {
40+
fmt.Printf("IBMCLOUD SL Command Directory\n")
41+
42+
slPlugin := new(sl_plugin.SoftlayerPlugin)
43+
slMeta := slPlugin.GetMetadata()
44+
sort.Slice(slMeta.Commands, func(i, j int) bool {
45+
one := fmt.Sprintf("%s %s", slMeta.Commands[i].Namespace, slMeta.Commands[i].Name)
46+
two := fmt.Sprintf("%s %s", slMeta.Commands[j].Namespace, slMeta.Commands[j].Name)
47+
return one < two
48+
})
49+
fmt.Printf("==============================================================\n")
50+
fileName := ""
51+
fileContent := ""
52+
// TODO: call-api, version and metadata need a special case or something for filename...
53+
for _, slCmd := range slMeta.Commands {
54+
thisFileName := fmt.Sprintf("cli_%s.md", slCmd.Namespace)
55+
thisFileName = strings.ReplaceAll(thisFileName, " ", "_")
56+
if thisFileName != fileName {
57+
fileName = thisFileName
58+
fmt.Printf("NameSpace: %s Name: %s FIleName: %s\n", slCmd.Namespace, slCmd.Name, fileName)
59+
if fileContent != "" {
60+
fmt.Printf("Here is where I would write out to a file...\n")
61+
fileContent = ""
62+
}
63+
}
64+
65+
sort.Slice(slCmd.Flags, func(i, j int) bool {
66+
return slCmd.Flags[i].Name < slCmd.Flags[j].Name
67+
})
68+
// for _, slCmdFlag := range slCmd.Flags {
69+
// fmt.Printf("\tFlag: %s: %s\n", slCmdFlag.Name, slCmdFlag.Description)
70+
71+
// }
72+
// fmt.Printf("\t--------------------------------\n")
73+
// fmt.Printf("\tDescription: %s\n", slCmd.Description)
74+
// fmt.Printf("\t--------------------------------\n")
75+
// fmt.Printf("\tUsage: %s\n", slCmd.Usage)
76+
// fmt.Printf("==============================================================\n")
77+
}
78+
}
79+
80+
81+
// This function uses the build in Cobra documentation generator, its fine.
82+
func CobraDocs() {
2083
fmt.Printf("Generating Documentation\n")
2184

2285
var fakeUI *terminal.FakeUI

0 commit comments

Comments
 (0)