github.com/argoproj/argo-cd@v1.8.7/util/templates/normalizers.go (about)

     1  package templates
     2  
     3  import (
     4  	"strings"
     5  )
     6  
     7  const Indentation = `  `
     8  
     9  // Examples normalizes a command's examples to follow the conventions.
    10  func Examples(s string) string {
    11  	if len(s) == 0 {
    12  		return s
    13  	}
    14  	return normalizer{s}.trim().indent().string
    15  }
    16  
    17  type normalizer struct {
    18  	string
    19  }
    20  
    21  func (s normalizer) trim() normalizer {
    22  	s.string = strings.TrimSpace(s.string)
    23  	return s
    24  }
    25  
    26  func (s normalizer) indent() normalizer {
    27  	indentedLines := []string{}
    28  	for _, line := range strings.Split(s.string, "\n") {
    29  		trimmed := strings.TrimSpace(line)
    30  		indented := Indentation + trimmed
    31  		indentedLines = append(indentedLines, indented)
    32  	}
    33  	s.string = strings.Join(indentedLines, "\n")
    34  	return s
    35  }