diff --git a/cmd/commands_test.go b/cmd/commands_test.go index 5ad441d4..2099111d 100644 --- a/cmd/commands_test.go +++ b/cmd/commands_test.go @@ -397,6 +397,78 @@ func TestReadScalarLengthCmd(t *testing.T) { test.AssertResult(t, "4\n", result.Output) } +func TestReadDoubleQuotedStringCmd(t *testing.T) { + content := `name: "meow face"` + filename := test.WriteTempYamlFile(content) + defer test.RemoveTempYamlFile(filename) + + cmd := getRootCommand() + result := test.RunCmd(cmd, fmt.Sprintf("read %s name", filename)) + if result.Error != nil { + t.Error(result.Error) + } + test.AssertResult(t, "meow face\n", result.Output) +} + +func TestReadSingleQuotedStringCmd(t *testing.T) { + content := `name: 'meow face'` + filename := test.WriteTempYamlFile(content) + defer test.RemoveTempYamlFile(filename) + + cmd := getRootCommand() + result := test.RunCmd(cmd, fmt.Sprintf("read %s name", filename)) + if result.Error != nil { + t.Error(result.Error) + } + test.AssertResult(t, "meow face\n", result.Output) +} + +func TestReadQuotedMultinlineStringCmd(t *testing.T) { + content := `test: | + abcdefg + hijklmno +` + filename := test.WriteTempYamlFile(content) + defer test.RemoveTempYamlFile(filename) + + cmd := getRootCommand() + result := test.RunCmd(cmd, fmt.Sprintf("read %s test", filename)) + if result.Error != nil { + t.Error(result.Error) + } + expectedOutput := `abcdefg +hijklmno + +` + test.AssertResult(t, expectedOutput, result.Output) +} + +func TestReadBooleanCmd(t *testing.T) { + content := `name: true` + filename := test.WriteTempYamlFile(content) + defer test.RemoveTempYamlFile(filename) + + cmd := getRootCommand() + result := test.RunCmd(cmd, fmt.Sprintf("read %s name", filename)) + if result.Error != nil { + t.Error(result.Error) + } + test.AssertResult(t, "true\n", result.Output) +} + +func TestReadNumberCmd(t *testing.T) { + content := `name: 32.13` + filename := test.WriteTempYamlFile(content) + defer test.RemoveTempYamlFile(filename) + + cmd := getRootCommand() + result := test.RunCmd(cmd, fmt.Sprintf("read %s name", filename)) + if result.Error != nil { + t.Error(result.Error) + } + test.AssertResult(t, "32.13\n", result.Output) +} + func TestReadDeepSplatCmd(t *testing.T) { cmd := getRootCommand() result := test.RunCmd(cmd, "read -p pv ../examples/sample.yaml b.**") diff --git a/cmd/utils.go b/cmd/utils.go index bd5a88c7..879630c5 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -103,6 +103,9 @@ 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 { + return writeString(writer, node.Value+"\n") + } if outputToJSON { encoder = yqlib.NewJsonEncoder(writer, prettyPrint, indent) } else { diff --git a/cmd/version.go b/cmd/version.go index 02b46d8d..5b843f04 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -11,7 +11,7 @@ var ( GitDescribe string // Version is main version number that is being run at the moment. - Version = "3.2.0" + Version = "3.2.1" // VersionPrerelease is a pre-release marker for the version. If this is "" (empty string) // then it means that it is a final release. Otherwise, this is a pre-release diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 6bf1f8e6..a2a949d9 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: yq -version: '3.2.0' +version: '3.2.1' summary: A lightweight and portable command-line YAML processor description: | The aim of the project is to be the jq or sed of yaml files.