mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Added shorthand output formats
This commit is contained in:
parent
10d4eb3381
commit
d18aa3e9e0
@ -37,10 +37,32 @@ EOL
|
|||||||
}
|
}
|
||||||
EOM
|
EOM
|
||||||
|
|
||||||
X=$(./yq e -o=json test.yml)
|
X=$(./yq e --output-format=json test.yml)
|
||||||
assertEquals "$expected" "$X"
|
assertEquals "$expected" "$X"
|
||||||
|
|
||||||
X=$(./yq ea -o=json test.yml)
|
X=$(./yq ea --output-format=json test.yml)
|
||||||
|
assertEquals "$expected" "$X"
|
||||||
|
}
|
||||||
|
|
||||||
|
testOutputJsonShort() {
|
||||||
|
cat >test.yml <<EOL
|
||||||
|
a: {b: ["cat"]}
|
||||||
|
EOL
|
||||||
|
|
||||||
|
read -r -d '' expected << EOM
|
||||||
|
{
|
||||||
|
"a": {
|
||||||
|
"b": [
|
||||||
|
"cat"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOM
|
||||||
|
|
||||||
|
X=$(./yq e -o=j test.yml)
|
||||||
|
assertEquals "$expected" "$X"
|
||||||
|
|
||||||
|
X=$(./yq ea -o=j test.yml)
|
||||||
assertEquals "$expected" "$X"
|
assertEquals "$expected" "$X"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,10 +75,26 @@ EOL
|
|||||||
a.b.c.0 = cat
|
a.b.c.0 = cat
|
||||||
EOM
|
EOM
|
||||||
|
|
||||||
X=$(./yq e -o=props test.yml)
|
X=$(./yq e --output-format=props test.yml)
|
||||||
assertEquals "$expected" "$X"
|
assertEquals "$expected" "$X"
|
||||||
|
|
||||||
X=$(./yq ea -o=props test.yml)
|
X=$(./yq ea --output-format=props test.yml)
|
||||||
|
assertEquals "$expected" "$X"
|
||||||
|
}
|
||||||
|
|
||||||
|
testOutputPropertiesShort() {
|
||||||
|
cat >test.yml <<EOL
|
||||||
|
a: {b: {c: ["cat"]}}
|
||||||
|
EOL
|
||||||
|
|
||||||
|
read -r -d '' expected << EOM
|
||||||
|
a.b.c.0 = cat
|
||||||
|
EOM
|
||||||
|
|
||||||
|
X=$(./yq e -o=p test.yml)
|
||||||
|
assertEquals "$expected" "$X"
|
||||||
|
|
||||||
|
X=$(./yq ea -o=p test.yml)
|
||||||
assertEquals "$expected" "$X"
|
assertEquals "$expected" "$X"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ See https://mikefarah.gitbook.io/yq/ for detailed documentation and examples.`,
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rootCmd.PersistentFlags().StringVarP(&outputFormat, "output-format", "o", "yaml", "[yaml|json|props] output format type.")
|
rootCmd.PersistentFlags().StringVarP(&outputFormat, "output-format", "o", "yaml", "[yaml|y|json|j|props|p] 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(&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 (---)")
|
rootCmd.PersistentFlags().BoolVarP(&noDocSeparators, "no-doc", "N", false, "Don't print document separators (---)")
|
||||||
|
|
||||||
|
@ -27,11 +27,11 @@ const (
|
|||||||
|
|
||||||
func OutputFormatFromString(format string) (PrinterOutputFormat, error) {
|
func OutputFormatFromString(format string) (PrinterOutputFormat, error) {
|
||||||
switch format {
|
switch format {
|
||||||
case "yaml":
|
case "yaml", "y":
|
||||||
return YamlOutputFormat, nil
|
return YamlOutputFormat, nil
|
||||||
case "json":
|
case "json", "j":
|
||||||
return JsonOutputFormat, nil
|
return JsonOutputFormat, nil
|
||||||
case "props":
|
case "props", "p":
|
||||||
return PropsOutputFormat, nil
|
return PropsOutputFormat, nil
|
||||||
default:
|
default:
|
||||||
return 0, fmt.Errorf("Unknown fromat '%v' please use [yaml|json|props]", format)
|
return 0, fmt.Errorf("Unknown fromat '%v' please use [yaml|json|props]", format)
|
||||||
|
Loading…
Reference in New Issue
Block a user