fix(clustertool): new round of indent fixes
This commit is contained in:
@@ -2,9 +2,30 @@ package helper
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func MarshalYaml(buf *bytes.Buffer, v interface{}) error {
|
||||
enc := YamlNewEncoder(buf)
|
||||
return enc.Encode(v)
|
||||
var tmpBuf bytes.Buffer
|
||||
enc := yaml.NewEncoder(&tmpBuf)
|
||||
enc.SetIndent(2)
|
||||
defer enc.Close()
|
||||
|
||||
if err := enc.Encode(v); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Remove indent from top-level keys (lines that are not indented)
|
||||
lines := strings.Split(tmpBuf.String(), "\n")
|
||||
for _, line := range lines {
|
||||
if strings.HasPrefix(line, " ") {
|
||||
buf.WriteString(line + "\n")
|
||||
} else {
|
||||
buf.WriteString(strings.TrimLeft(line, " ") + "\n")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"io"
|
||||
|
||||
"sigs.k8s.io/yaml"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// Encoder is a custom encoder for YAML that writes to an io.Writer.
|
||||
|
||||
Reference in New Issue
Block a user