mirror of
https://github.com/mikefarah/yq.git
synced 2025-02-26 09:42:29 +00:00
Fixed toJson command line option, should only apply to read command
This commit is contained in:
parent
df08b055cf
commit
b3b60665e4
@ -71,7 +71,6 @@ Available Commands:
|
|||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
-h, --help help for yq
|
-h, --help help for yq
|
||||||
-j, --tojson output as json
|
|
||||||
-t, --trim trim yaml output (default true)
|
-t, --trim trim yaml output (default true)
|
||||||
-v, --verbose verbose mode
|
-v, --verbose verbose mode
|
||||||
-V, --version Print version information and quit
|
-V, --version Print version information and quit
|
||||||
|
@ -73,30 +73,6 @@ func TestRootCmd_TrimShort(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRootCmd_ToJsonLong(t *testing.T) {
|
|
||||||
cmd := getRootCommand()
|
|
||||||
result := runCmd(cmd, "--tojson")
|
|
||||||
if result.Error != nil {
|
|
||||||
t.Error(result.Error)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !outputToJSON {
|
|
||||||
t.Error("Expected outputToJSON to be true")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRootCmd_ToJsonShort(t *testing.T) {
|
|
||||||
cmd := getRootCommand()
|
|
||||||
result := runCmd(cmd, "-j")
|
|
||||||
if result.Error != nil {
|
|
||||||
t.Error(result.Error)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !outputToJSON {
|
|
||||||
t.Error("Expected outputToJSON to be true")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRootCmd_VersionShort(t *testing.T) {
|
func TestRootCmd_VersionShort(t *testing.T) {
|
||||||
cmd := getRootCommand()
|
cmd := getRootCommand()
|
||||||
result := runCmd(cmd, "-V")
|
result := runCmd(cmd, "-V")
|
||||||
@ -302,7 +278,16 @@ func TestReadCmd_NoTrim(t *testing.T) {
|
|||||||
|
|
||||||
func TestReadCmd_ToJson(t *testing.T) {
|
func TestReadCmd_ToJson(t *testing.T) {
|
||||||
cmd := getRootCommand()
|
cmd := getRootCommand()
|
||||||
result := runCmd(cmd, "-j read examples/sample.yaml b.c")
|
result := runCmd(cmd, "read -j examples/sample.yaml b.c")
|
||||||
|
if result.Error != nil {
|
||||||
|
t.Error(result.Error)
|
||||||
|
}
|
||||||
|
assertResult(t, "2\n", result.Output)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReadCmd_ToJsonLong(t *testing.T) {
|
||||||
|
cmd := getRootCommand()
|
||||||
|
result := runCmd(cmd, "read --tojson examples/sample.yaml b.c")
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
t.Error(result.Error)
|
t.Error(result.Error)
|
||||||
}
|
}
|
||||||
@ -343,17 +328,6 @@ func TestNewCmd_Verbose(t *testing.T) {
|
|||||||
assertResult(t, expectedOutput, result.Output)
|
assertResult(t, expectedOutput, result.Output)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewCmd_ToJson(t *testing.T) {
|
|
||||||
cmd := getRootCommand()
|
|
||||||
result := runCmd(cmd, "-j new b.c 3")
|
|
||||||
if result.Error != nil {
|
|
||||||
t.Error(result.Error)
|
|
||||||
}
|
|
||||||
expectedOutput := `{"b":{"c":3}}
|
|
||||||
`
|
|
||||||
assertResult(t, expectedOutput, result.Output)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestWriteCmd(t *testing.T) {
|
func TestWriteCmd(t *testing.T) {
|
||||||
content := `b:
|
content := `b:
|
||||||
c: 3
|
c: 3
|
||||||
|
12
yq.go
12
yq.go
@ -66,7 +66,6 @@ func newCommandCLI() *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rootCmd.PersistentFlags().BoolVarP(&trimOutput, "trim", "t", true, "trim yaml output")
|
rootCmd.PersistentFlags().BoolVarP(&trimOutput, "trim", "t", true, "trim yaml output")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&outputToJSON, "tojson", "j", false, "output as json")
|
|
||||||
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose mode")
|
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose mode")
|
||||||
rootCmd.Flags().BoolVarP(&version, "version", "V", false, "Print version information and quit")
|
rootCmd.Flags().BoolVarP(&version, "version", "V", false, "Print version information and quit")
|
||||||
|
|
||||||
@ -86,7 +85,7 @@ func createReadCmd() *cobra.Command {
|
|||||||
var cmdRead = &cobra.Command{
|
var cmdRead = &cobra.Command{
|
||||||
Use: "read [yaml_file] [path]",
|
Use: "read [yaml_file] [path]",
|
||||||
Aliases: []string{"r"},
|
Aliases: []string{"r"},
|
||||||
Short: "yq r [--doc/-d document_index] sample.yaml a.b.c",
|
Short: "yq r [--doc/-d index] sample.yaml a.b.c",
|
||||||
Example: `
|
Example: `
|
||||||
yq read things.yaml a.b.c
|
yq read things.yaml a.b.c
|
||||||
yq r - a.b.c (reads from stdin)
|
yq r - a.b.c (reads from stdin)
|
||||||
@ -97,7 +96,8 @@ yq r things.yaml a.array[*].blah
|
|||||||
Long: "Outputs the value of the given path in the yaml file to STDOUT",
|
Long: "Outputs the value of the given path in the yaml file to STDOUT",
|
||||||
RunE: readProperty,
|
RunE: readProperty,
|
||||||
}
|
}
|
||||||
cmdRead.PersistentFlags().StringVarP(&docIndex, "doc", "d", "0", "process document index number (0 based")
|
cmdRead.PersistentFlags().StringVarP(&docIndex, "doc", "d", "0", "process document index number, 0 based")
|
||||||
|
cmdRead.PersistentFlags().BoolVarP(&outputToJSON, "tojson", "j", false, "output as json")
|
||||||
return cmdRead
|
return cmdRead
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ func createWriteCmd() *cobra.Command {
|
|||||||
var cmdWrite = &cobra.Command{
|
var cmdWrite = &cobra.Command{
|
||||||
Use: "write [yaml_file] [path] [value]",
|
Use: "write [yaml_file] [path] [value]",
|
||||||
Aliases: []string{"w"},
|
Aliases: []string{"w"},
|
||||||
Short: "yq w [--inplace/-i] [--script/-s script_file] [--doc/-d document_index] sample.yaml a.b.c newValueForC",
|
Short: "yq w [--inplace/-i] [--script/-s script_file] [--doc/-d index] sample.yaml a.b.c newValueForC",
|
||||||
Example: `
|
Example: `
|
||||||
yq write things.yaml a.b.c cat
|
yq write things.yaml a.b.c cat
|
||||||
yq write --inplace things.yaml a.b.c cat
|
yq write --inplace things.yaml a.b.c cat
|
||||||
@ -140,7 +140,7 @@ func createDeleteCmd() *cobra.Command {
|
|||||||
var cmdDelete = &cobra.Command{
|
var cmdDelete = &cobra.Command{
|
||||||
Use: "delete [yaml_file] [path]",
|
Use: "delete [yaml_file] [path]",
|
||||||
Aliases: []string{"d"},
|
Aliases: []string{"d"},
|
||||||
Short: "yq d [--inplace/-i] [--doc/-d document_index] sample.yaml a.b.c",
|
Short: "yq d [--inplace/-i] [--doc/-d index] sample.yaml a.b.c",
|
||||||
Example: `
|
Example: `
|
||||||
yq delete things.yaml a.b.c
|
yq delete things.yaml a.b.c
|
||||||
yq delete --inplace things.yaml a.b.c
|
yq delete --inplace things.yaml a.b.c
|
||||||
@ -183,7 +183,7 @@ func createMergeCmd() *cobra.Command {
|
|||||||
var cmdMerge = &cobra.Command{
|
var cmdMerge = &cobra.Command{
|
||||||
Use: "merge [initial_yaml_file] [additional_yaml_file]...",
|
Use: "merge [initial_yaml_file] [additional_yaml_file]...",
|
||||||
Aliases: []string{"m"},
|
Aliases: []string{"m"},
|
||||||
Short: "yq m [--inplace/-i] [--doc/-d document_index] [--overwrite/-x] sample.yaml sample2.yaml",
|
Short: "yq m [--inplace/-i] [--doc/-d index] [--overwrite/-x] sample.yaml sample2.yaml",
|
||||||
Example: `
|
Example: `
|
||||||
yq merge things.yaml other.yaml
|
yq merge things.yaml other.yaml
|
||||||
yq merge --inplace things.yaml other.yaml
|
yq merge --inplace things.yaml other.yaml
|
||||||
|
Loading…
Reference in New Issue
Block a user