Dont unwrap json output by default

This commit is contained in:
Mike Farah 2020-04-14 14:11:44 +10:00
parent dfdbbbb24a
commit 33e35d10dd
2 changed files with 16 additions and 1 deletions

View File

@ -109,6 +109,21 @@ func TestReadUnwrapCmd(t *testing.T) {
test.AssertResult(t, "'frog' # my favourite\n", result.Output)
}
func TestReadUnwrapJsonByDefaultCmd(t *testing.T) {
content := `b: 'frog' # my favourite`
filename := test.WriteTempYamlFile(content)
defer test.RemoveTempYamlFile(filename)
cmd := getRootCommand()
result := test.RunCmd(cmd, fmt.Sprintf("read %s b -j", filename))
if result.Error != nil {
t.Error(result.Error)
}
test.AssertResult(t, "\"frog\"\n", result.Output)
}
func TestCompareSameCmd(t *testing.T) {
cmd := getRootCommand()
result := test.RunCmd(cmd, "compare ../examples/data1.yaml ../examples/data1.yaml")

View File

@ -103,7 +103,7 @@ func transformNode(node *yaml.Node) *yaml.Node {
func printNode(node *yaml.Node, writer io.Writer) error {
var encoder yqlib.Encoder
if node.Kind == yaml.ScalarNode && unwrapScalar {
if node.Kind == yaml.ScalarNode && unwrapScalar && !outputToJSON {
return writeString(writer, node.Value+"\n")
}
if outputToJSON {