Skip to content

Commit f1a98cb

Browse files
updated docs generation program
1 parent 1ab0825 commit f1a98cb

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

docs/main.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"strings"
77
"encoding/json"
8+
"regexp"
89

910
"text/template"
1011
// "sort"
@@ -99,6 +100,7 @@ func CliDocs() {
99100
func PrintMakrdown(cmd SlCmdGroup) {
100101

101102
var cmdTemplate = `<!-- THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT -->
103+
<!-- markdownlint-disable first-heading-h1 lastupdated-misformat-or-missing frontmatter-yaml -->
102104
{{range .Commands}}
103105
## ibmcloud {{.CommandPath}}
104106
{: #{{.CommandShortLink}}}
@@ -130,8 +132,26 @@ ibmcloud {{.Use}}
130132
}
131133

132134
func getLongHelp(helpString string) string {
135+
// Removes some ugly empty lines sometimes.
136+
empty_line := regexp.MustCompile(`(?m)^(\t)+$`)
137+
helpString = empty_line.ReplaceAllString(helpString, "")
133138
helpString = strings.ReplaceAll(helpString, "${COMMAND_NAME}", "ibmcloud")
134-
helpString = strings.ReplaceAll(helpString, "EXAMPLE:", "**Examples**:\n")
139+
example_regex := regexp.MustCompile(`(?i)Example:+`)
140+
helpString = example_regex.ReplaceAllString(helpString, "**Examples**:\n")
141+
// for 'indented-by-two'
142+
indent_regex := regexp.MustCompile(`(?m)^\s{2}(\S)`)
143+
helpString = indent_regex.ReplaceAllString(helpString, " $1")
144+
145+
return getFlagHelp(helpString)
146+
}
147+
148+
func getFlagHelp(helpString string) string {
149+
// for 'no-inline-html' errors
150+
fake_html_regex := regexp.MustCompile(`<([0-9A-Za-z_\-\.\s]+)>`)
151+
helpString = fake_html_regex.ReplaceAllString(helpString, "$1")
152+
// for 'no-reversed-links'
153+
fake_link_regex := regexp.MustCompile(`\)\[`)
154+
helpString = fake_link_regex.ReplaceAllString(helpString, ") [")
135155
return helpString
136156
}
137157

@@ -176,7 +196,7 @@ func buildSlCmdFlag(topCommand *cobra.Command) []SlCmdFlag {
176196
}
177197
thisFlag := SlCmdFlag{
178198
Name:flagName,
179-
Help: pflag.Usage,
199+
Help: getFlagHelp(pflag.Usage),
180200
Default: pflag.DefValue,
181201
}
182202
flags = append(flags, thisFlag)

0 commit comments

Comments
 (0)