|
5 | 5 | "os" |
6 | 6 | "strings" |
7 | 7 | "encoding/json" |
| 8 | + "regexp" |
8 | 9 |
|
9 | 10 | "text/template" |
10 | 11 | // "sort" |
@@ -99,6 +100,7 @@ func CliDocs() { |
99 | 100 | func PrintMakrdown(cmd SlCmdGroup) { |
100 | 101 |
|
101 | 102 | var cmdTemplate = `<!-- THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT --> |
| 103 | +<!-- markdownlint-disable first-heading-h1 lastupdated-misformat-or-missing frontmatter-yaml --> |
102 | 104 | {{range .Commands}} |
103 | 105 | ## ibmcloud {{.CommandPath}} |
104 | 106 | {: #{{.CommandShortLink}}} |
@@ -130,8 +132,26 @@ ibmcloud {{.Use}} |
130 | 132 | } |
131 | 133 |
|
132 | 134 | 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, "") |
133 | 138 | 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, ") [") |
135 | 155 | return helpString |
136 | 156 | } |
137 | 157 |
|
@@ -176,7 +196,7 @@ func buildSlCmdFlag(topCommand *cobra.Command) []SlCmdFlag { |
176 | 196 | } |
177 | 197 | thisFlag := SlCmdFlag{ |
178 | 198 | Name:flagName, |
179 | | - Help: pflag.Usage, |
| 199 | + Help: getFlagHelp(pflag.Usage), |
180 | 200 | Default: pflag.DefValue, |
181 | 201 | } |
182 | 202 | flags = append(flags, thisFlag) |
|
0 commit comments