Updated to use -o for output format

This commit is contained in:
Mike Farah 2021-08-20 13:35:57 +10:00
parent 043e9128d7
commit 10d4eb3381
3 changed files with 69 additions and 2 deletions

View File

@ -0,0 +1,63 @@
#!/bin/bash
testOutputJsonDeprecated() {
cat >test.yml <<EOL
a: {b: ["cat"]}
EOL
read -r -d '' expected << EOM
{
"a": {
"b": [
"cat"
]
}
}
EOM
X=$(./yq e -j test.yml)
assertEquals "$expected" "$X"
X=$(./yq ea -j test.yml)
assertEquals "$expected" "$X"
}
testOutputJson() {
cat >test.yml <<EOL
a: {b: ["cat"]}
EOL
read -r -d '' expected << EOM
{
"a": {
"b": [
"cat"
]
}
}
EOM
X=$(./yq e -o=json test.yml)
assertEquals "$expected" "$X"
X=$(./yq ea -o=json test.yml)
assertEquals "$expected" "$X"
}
testOutputProperties() {
cat >test.yml <<EOL
a: {b: {c: ["cat"]}}
EOL
read -r -d '' expected << EOM
a.b.c.0 = cat
EOM
X=$(./yq e -o=props test.yml)
assertEquals "$expected" "$X"
X=$(./yq ea -o=props test.yml)
assertEquals "$expected" "$X"
}
source ./scripts/shunit2

View File

@ -43,12 +43,12 @@ See https://mikefarah.gitbook.io/yq/ for detailed documentation and examples.`,
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose mode")
rootCmd.PersistentFlags().BoolVarP(&outputToJSON, "tojson", "j", false, "(deprecated) output as json. Set indent to 0 to print json in one line.")
err := rootCmd.PersistentFlags().MarkDeprecated("tojson", "please use -t=json instead")
err := rootCmd.PersistentFlags().MarkDeprecated("tojson", "please use -o=json instead")
if err != nil {
panic(err)
}
rootCmd.PersistentFlags().StringVarP(&outputFormat, "to-type", "t", "yaml", "[yaml|json|props] output format type.")
rootCmd.PersistentFlags().StringVarP(&outputFormat, "output-format", "o", "yaml", "[yaml|json|props] output format type.")
rootCmd.PersistentFlags().BoolVarP(&nullInput, "null-input", "n", false, "Don't read input, simply evaluate the expression given. Useful for creating yaml docs from scratch.")
rootCmd.PersistentFlags().BoolVarP(&noDocSeparators, "no-doc", "N", false, "Don't print document separators (---)")

4
release_notes.txt Normal file
View File

@ -0,0 +1,4 @@
4.12.0:
- Can now convert yaml to properties properties format (`-o=props`), See [] for more info.
- Fixed document header/footer comment handling when merging (https://github.com/mikefarah/yq/issues/919)
- pretty print yaml 1.1 compatibility (https://github.com/mikefarah/yq/issues/914)