Skip to content

Commit ca8c2e2

Browse files
committed
markdown: use stringbuilder.WriteString()
This makes my IDE happier, as there's less unhandled errors. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 64ee549 commit ca8c2e2

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

clidocstool_md.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -157,43 +157,43 @@ func mdCmdOutput(cmd *cobra.Command, old string) (string, error) {
157157
desc = cmd.Long
158158
}
159159
if desc != "" {
160-
fmt.Fprintf(b, "%s\n\n", desc)
160+
b.WriteString(desc + "\n\n")
161161
}
162162

163163
if aliases := getAliases(cmd); len(aliases) != 0 {
164-
fmt.Fprint(b, "### Aliases\n\n")
165-
fmt.Fprint(b, "`"+strings.Join(aliases, "`, `")+"`")
166-
fmt.Fprint(b, "\n\n")
164+
b.WriteString("### Aliases\n\n")
165+
b.WriteString("`" + strings.Join(aliases, "`, `") + "`")
166+
b.WriteString("\n\n")
167167
}
168168

169169
if len(cmd.Commands()) != 0 {
170-
fmt.Fprint(b, "### Subcommands\n\n")
171-
fmt.Fprint(b, "| Name | Description |\n")
172-
fmt.Fprint(b, "| --- | --- |\n")
170+
b.WriteString("### Subcommands\n\n")
171+
b.WriteString("| Name | Description |\n")
172+
b.WriteString("| --- | --- |\n")
173173
for _, c := range cmd.Commands() {
174-
fmt.Fprintf(b, "| [`%s`](%s) | %s |\n", c.Name(), mdFilename(c), c.Short)
174+
b.WriteString(fmt.Sprintf("| [`%s`](%s) | %s |\n", c.Name(), mdFilename(c), c.Short))
175175
}
176-
fmt.Fprint(b, "\n\n")
176+
b.WriteString("\n\n")
177177
}
178178

179179
// add inherited flags before checking for flags availability
180180
cmd.Flags().AddFlagSet(cmd.InheritedFlags())
181181

182182
if cmd.Flags().HasAvailableFlags() {
183-
fmt.Fprint(b, "### Options\n\n")
184-
fmt.Fprint(b, "| Name | Type | Default | Description |\n")
185-
fmt.Fprint(b, "| --- | --- | --- | --- |\n")
183+
b.WriteString("### Options\n\n")
184+
b.WriteString("| Name | Type | Default | Description |\n")
185+
b.WriteString("| --- | --- | --- | --- |\n")
186186

187187
cmd.Flags().VisitAll(func(f *pflag.Flag) {
188188
if f.Hidden {
189189
return
190190
}
191191
isLink := strings.Contains(old, "<a name=\""+f.Name+"\"></a>")
192-
fmt.Fprint(b, "| ")
192+
b.WriteString("| ")
193193
if f.Shorthand != "" {
194194
name := "`-" + f.Shorthand + "`"
195195
name = mdMakeLink(name, f.Name, f, isLink)
196-
fmt.Fprintf(b, "%s, ", name)
196+
b.WriteString(name + ", ")
197197
}
198198
name := "`--" + f.Name + "`"
199199
name = mdMakeLink(name, f.Name, f, isLink)
@@ -221,9 +221,9 @@ func mdCmdOutput(cmd *cobra.Command, old string) (string, error) {
221221
} else if cd, ok := cmd.Annotations[annotation.CodeDelimiter]; ok {
222222
usage = strings.ReplaceAll(usage, cd, "`")
223223
}
224-
fmt.Fprintf(b, "%s | %s | %s | %s |\n", mdEscapePipe(name), mdEscapePipe(ftype), mdEscapePipe(defval), mdReplaceNewline(mdEscapePipe(usage)))
224+
b.WriteString(fmt.Sprintf("%s | %s | %s | %s |\n", mdEscapePipe(name), mdEscapePipe(ftype), mdEscapePipe(defval), mdReplaceNewline(mdEscapePipe(usage))))
225225
})
226-
fmt.Fprintln(b, "")
226+
b.WriteString("\n")
227227
}
228228

229229
return b.String(), nil

0 commit comments

Comments
 (0)