Skip to content

Commit 6cd8e15

Browse files
slowly improving doc generation
1 parent 2a7d806 commit 6cd8e15

1 file changed

Lines changed: 26 additions & 21 deletions

File tree

docs/main.go

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ func CliDocs() {
8282
}
8383
if len(iCmd.Commands()) > 0 {
8484
thisCmdGroup.Commands = buildSlCmdDoc(iCmd)
85+
} else {
86+
// This is a single command, like 'call-api' and doesn't have sub-commands
87+
thisCmdGroup.Commands = []SlCmdDoc{cobraToSl(iCmd, "")}
8588
}
8689
PrintMakrdown(thisCmdGroup)
8790
CmdGroups = append(CmdGroups, thisCmdGroup)
@@ -96,11 +99,6 @@ func CliDocs() {
9699
func PrintMakrdown(cmd SlCmdGroup) {
97100

98101
var cmdTemplate = `<!-- THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT -->
99-
# ibmcloud sl {{.Name}}
100-
{: #{{.CommandShortLink}}}
101-
102-
{{.Help}}
103-
104102
{{range .Commands}}
105103
## ibmcloud {{.CommandPath}}
106104
{: #{{.CommandShortLink}}}
@@ -140,27 +138,34 @@ func getLongHelp(helpString string) string {
140138
func buildSlCmdDoc(topCommand *cobra.Command) []SlCmdDoc {
141139
docs := []SlCmdDoc{}
142140
for _, iCmd := range topCommand.Commands() {
143-
shortName := fmt.Sprintf("sl_%s_%s", topCommand.Name(), iCmd.Name())
144-
shortName = strings.ReplaceAll(shortName, " ", "_")
145-
shortName = strings.ReplaceAll(shortName, "-", "_")
146-
longHelp := getLongHelp(iCmd.Long)
147-
thisDoc := SlCmdDoc{
148-
Name: iCmd.Name(),
149-
CommandShortLink: shortName,
150-
CommandPath: iCmd.CommandPath(),
151-
Use: iCmd.UseLine(),
152-
Flags: nil,
153-
Help: iCmd.Short,
154-
LongHelp: longHelp,
155-
Backtick: "```",
156-
}
157-
thisDoc.Flags = buildSlCmdFlag(iCmd)
158-
141+
thisDoc := cobraToSl(iCmd, topCommand.Name())
159142
docs = append(docs, thisDoc)
160143
}
161144
return docs
162145
}
163146

147+
func cobraToSl(iCmd *cobra.Command, tlcmd string) SlCmdDoc {
148+
149+
shortName := fmt.Sprintf("sl_%s_%s", tlcmd, iCmd.Name())
150+
shortName = strings.ReplaceAll(shortName, " ", "_")
151+
shortName = strings.ReplaceAll(shortName, "-", "_")
152+
longHelp := getLongHelp(iCmd.Long)
153+
thisDoc := SlCmdDoc{
154+
Name: iCmd.Name(),
155+
CommandShortLink: shortName,
156+
CommandPath: iCmd.CommandPath(),
157+
Use: iCmd.UseLine(),
158+
Flags: nil,
159+
Help: iCmd.Short,
160+
LongHelp: longHelp,
161+
Backtick: "```",
162+
}
163+
thisDoc.Flags = buildSlCmdFlag(iCmd)
164+
165+
return thisDoc
166+
167+
}
168+
164169
func buildSlCmdFlag(topCommand *cobra.Command) []SlCmdFlag {
165170
flags := []SlCmdFlag{}
166171
flagSet := topCommand.Flags()

0 commit comments

Comments
 (0)