Files
argo-cd/util/templates/normalizers.go
Matthieu MOREL a369ae2cf6 chore(util): Fix modernize linter (#26300)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2026-02-06 17:17:17 -05:00

36 lines
686 B
Go

package templates
import (
"strings"
)
const Indentation = ` `
// Examples normalizes a command's examples to follow the conventions.
func Examples(s string) string {
if s == "" {
return s
}
return normalizer{s}.trim().indent().string
}
type normalizer struct {
string
}
func (s normalizer) trim() normalizer {
s.string = strings.TrimSpace(s.string)
return s
}
func (s normalizer) indent() normalizer {
indentedLines := []string{}
for line := range strings.SplitSeq(s.string, "\n") {
trimmed := strings.TrimSpace(line)
indented := Indentation + trimmed
indentedLines = append(indentedLines, indented)
}
s.string = strings.Join(indentedLines, "\n")
return s
}