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:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user