Skip to content

Commit 9731b8f

Browse files
author
Antoine Pelisse
committed
Add ToYAML function to Marshal
1 parent 20f6545 commit 9731b8f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

internal/cli/operation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
"io"
2222
"io/ioutil"
2323

24-
"gopkg.in/yaml.v2"
2524
"sigs.k8s.io/structured-merge-diff/typed"
25+
"sigs.k8s.io/structured-merge-diff/value"
2626
)
2727

2828
type Operation interface {
@@ -114,7 +114,7 @@ func (m merge) Execute(w io.Writer) error {
114114
return err
115115
}
116116

117-
yaml, err := yaml.Marshal(out.AsValue().Unstructured())
117+
yaml, err := value.ToYAML(out.AsValue())
118118
if err != nil {
119119
return err
120120
}

value/value.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"strings"
2424

2525
jsoniter "github.com/json-iterator/go"
26+
"gopkg.in/yaml.v2"
2627
)
2728

2829
var (
@@ -118,6 +119,11 @@ func WriteJSONStream(v Value, stream *jsoniter.Stream) {
118119
stream.WriteVal(v.Unstructured())
119120
}
120121

122+
// ToYAML marshals a value as YAML.
123+
func ToYAML(v Value) ([]byte, error) {
124+
return yaml.Marshal(v.Unstructured())
125+
}
126+
121127
// Equals returns true iff the two values are equal.
122128
func Equals(lhs, rhs Value) bool {
123129
if lhs.IsFloat() || rhs.IsFloat() {

0 commit comments

Comments
 (0)