mirror of
https://github.com/rancher/norman.git
synced 2025-09-24 12:38:49 +00:00
Add yaml formatting for pretty edit mode
This commit is contained in:
@@ -3,10 +3,15 @@ package types
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/ghodss/yaml"
|
"github.com/ghodss/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
commenter = regexp.MustCompile("(?m)^( *)zzz#\\((.*)\\)\\((.*)\\)([a-z]+.*):(.*)")
|
||||||
|
)
|
||||||
|
|
||||||
func JSONEncoder(writer io.Writer, v interface{}) error {
|
func JSONEncoder(writer io.Writer, v interface{}) error {
|
||||||
return json.NewEncoder(writer).Encode(v)
|
return json.NewEncoder(writer).Encode(v)
|
||||||
}
|
}
|
||||||
@@ -20,6 +25,8 @@ func YAMLEncoder(writer io.Writer, v interface{}) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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)
|
_, err = writer.Write(buf)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user