Skip to content

Commit 68eb7d3

Browse files
Working on getting docs formatted nicely
1 parent 25ef347 commit 68eb7d3

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

docs/main.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ type SlCmdDoc struct {
5757
Flags []SlCmdFlag
5858
Help string
5959
LongHelp string
60+
Backtick string
61+
CommandPath string
6062
}
6163

6264
// For a commands flags
@@ -80,6 +82,7 @@ func CliDocs() {
8082
CommandShortLink: fmt.Sprintf("sl_%v", shortName),
8183
Commands: nil,
8284
Help: iCmd.Short,
85+
8386
}
8487
if len(iCmd.Commands()) > 0 {
8588
thisCmdGroup.Commands = buildSlCmdDoc(iCmd)
@@ -97,23 +100,30 @@ func CliDocs() {
97100
func PrintMakrdown(cmd SlCmdGroup) {
98101

99102
var cmdTemplate = `
100-
## {{.Name}}
103+
# ibmcloud sl {{.Name}}
101104
{: #{{.CommandShortLink}}}
102105
103106
{{.Help}}
104107
105108
{{range .Commands}}
106-
#### {{.Name}}
109+
## ibmcloud {{.CommandPath}}
107110
{: #{{.CommandShortLink}}}
108111
109112
{{.Help}}
110113
111-
**Command options**:
112-
{{range .Flags}}
113-
--{{.Name}} {{.Help}}
114-
{{end}}
115-
116114
{{.LongHelp}}
115+
116+
{{.Backtick}}bash
117+
ibmcloud {{.Use}}
118+
{{.Backtick}}
119+
{: codeblock}
120+
121+
{{if .Flags}}
122+
**Flags**:
123+
{{range .Flags}}
124+
--{{.Name}} {{.Help}}
125+
{{end}}
126+
{{end}}
117127
{{end}}
118128
119129
`
@@ -131,15 +141,19 @@ func PrintMakrdown(cmd SlCmdGroup) {
131141
func buildSlCmdDoc(topCommand *cobra.Command) []SlCmdDoc {
132142
docs := []SlCmdDoc{}
133143
for _, iCmd := range topCommand.Commands() {
134-
shortName := strings.ReplaceAll(iCmd.Name(), " ", "_")
135-
shortName = strings.ReplaceAll(iCmd.Name(), "-", "_")
144+
shortName := fmt.Sprintf("sl_%s_%s", topCommand.Name(), iCmd.Name())
145+
shortName = strings.ReplaceAll(shortName, " ", "_")
146+
shortName = strings.ReplaceAll(shortName, "-", "_")
147+
136148
thisDoc := SlCmdDoc{
137149
Name: iCmd.Name(),
138150
CommandShortLink: shortName,
139-
Use: iCmd.Use,
151+
CommandPath: iCmd.CommandPath(),
152+
Use: iCmd.UseLine(),
140153
Flags: nil,
141154
Help: iCmd.Short,
142-
LongHelp: iCmd.Long,
155+
LongHelp: strings.ReplaceAll(iCmd.Long, "${COMMAND_NAME}", "ibmcloud"),
156+
Backtick: "```",
143157
}
144158
thisDoc.Flags = buildSlCmdFlag(iCmd)
145159

0 commit comments

Comments
 (0)