fix: replace string concatenation in loop with string builder (#505)

This commit is contained in:
Lars Müller 2023-08-24 18:52:15 +02:00 committed by GitHub
parent f0734709f0
commit 9a3f7a19cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -284,15 +284,16 @@ func executeCLI(cmd *cobra.Command, src *source, w io.Writer) error {
// trim lines
lines := strings.Split(string(out), "\n")
var content string
var cb strings.Builder
for i, s := range lines {
content += strings.TrimSpace(s)
cb.WriteString(strings.TrimSpace(s))
// don't add an artificial newline after the last split
if i+1 < len(lines) {
content += "\n"
cb.WriteString("\n")
}
}
content := cb.String()
// display
if pager || cmd.Flags().Changed("pager") {