mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
36 lines
686 B
Go
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
|
|
}
|