1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-23 20:18:51 +00:00

Add yaml formatting for pretty edit mode

This commit is contained in:
Darren Shepherd
2018-07-13 13:03:49 -07:00
parent 843a604715
commit c3512e7097

View File

@@ -3,10 +3,15 @@ package types
import (
"encoding/json"
"io"
"regexp"
"github.com/ghodss/yaml"
)
var (
commenter = regexp.MustCompile("(?m)^( *)zzz#\\((.*)\\)\\((.*)\\)([a-z]+.*):(.*)")
)
func JSONEncoder(writer io.Writer, v interface{}) error {
return json.NewEncoder(writer).Encode(v)
}
@@ -20,6 +25,8 @@ func YAMLEncoder(writer io.Writer, v interface{}) error {
if err != nil {
return err
}
//buf = commenter.ReplaceAll(buf, []byte("${1}# ${2}type: ${3}\n${1}# ${4}:${5}"))
buf = commenter.ReplaceAll(buf, []byte("${1}# ${4}:${5}"))
_, err = writer.Write(buf)
return err
}