diff --git a/examples/multiline-text.yaml b/examples/multiline-text.yaml new file mode 100644 index 00000000000..8ecccac3b16 --- /dev/null +++ b/examples/multiline-text.yaml @@ -0,0 +1,5 @@ +test: | + abcdefg + hijklmno + + diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index dc4b8ef7712..8b16e375466 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: yq -version: 1.14.0 +version: 1.14.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. diff --git a/version.go b/version.go index ca4adcd3fe7..9218e802ae6 100644 --- a/version.go +++ b/version.go @@ -11,7 +11,7 @@ var ( GitDescribe string // Version is main version number that is being run at the moment. - Version = "1.14.0" + Version = "1.14.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/yq.go b/yq.go index 8dde7046c5c..64720102a67 100644 --- a/yq.go +++ b/yq.go @@ -417,10 +417,21 @@ func toString(context interface{}) (string, error) { } func yamlToString(context interface{}) (string, error) { + switch context.(type) { + case string: + return context.(string), nil + default: + return marshalContext(context) + } +} + +func marshalContext(context interface{}) (string, error) { out, err := yaml.Marshal(context) + if err != nil { return "", fmt.Errorf("error printing yaml: %v", err) } + outStr := string(out) // trim the trailing new line as it's easier for a script to add // it in if required than to remove it diff --git a/yq_test.go b/yq_test.go index fa0dd3eb959..b00cc4b4750 100644 --- a/yq_test.go +++ b/yq_test.go @@ -47,6 +47,14 @@ application: MyApp`, formattedResult) } +func TestMultilineString(t *testing.T) { + testString := ` + abcd + efg` + formattedResult, _ := yamlToString(testString) + assertResult(t, testString, formattedResult) +} + func TestNewYaml(t *testing.T) { result, _ := newYaml([]string{"b.c", "3"}) formattedResult := fmt.Sprintf("%v", result)