mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Bugfix: Write empty array value
When the value is `[]` set the value to empty array instead of `'[]'`. Resolves: #21
This commit is contained in:
parent
6980be3800
commit
499974c27e
1
Makefile
1
Makefile
@ -74,6 +74,7 @@ install: build
|
|||||||
.PHONY: vendor
|
.PHONY: vendor
|
||||||
vendor: tmp/dev_image_id
|
vendor: tmp/dev_image_id
|
||||||
${DOCKRUN} bash ./scripts/vendor.sh
|
${DOCKRUN} bash ./scripts/vendor.sh
|
||||||
|
@chmod 664 vendor/vendor.json
|
||||||
|
|
||||||
# ----------------------------------------------
|
# ----------------------------------------------
|
||||||
# develop and test
|
# develop and test
|
||||||
|
@ -248,6 +248,22 @@ func TestWriteCmd(t *testing.T) {
|
|||||||
assertResult(t, expectedOutput, result.Output)
|
assertResult(t, expectedOutput, result.Output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWriteCmd_EmptyArray(t *testing.T) {
|
||||||
|
content := `b: 3`
|
||||||
|
filename := writeTempYamlFile(content)
|
||||||
|
defer removeTempYamlFile(filename)
|
||||||
|
|
||||||
|
cmd := getRootCommand()
|
||||||
|
result := runCmd(cmd, fmt.Sprintf("write %s a []", filename))
|
||||||
|
if result.Error != nil {
|
||||||
|
t.Error(result.Error)
|
||||||
|
}
|
||||||
|
expectedOutput := `b: 3
|
||||||
|
a: []
|
||||||
|
`
|
||||||
|
assertResult(t, expectedOutput, result.Output)
|
||||||
|
}
|
||||||
|
|
||||||
func TestWriteCmd_Error(t *testing.T) {
|
func TestWriteCmd_Error(t *testing.T) {
|
||||||
cmd := getRootCommand()
|
cmd := getRootCommand()
|
||||||
result := runCmd(cmd, "write")
|
result := runCmd(cmd, "write")
|
||||||
|
3
yaml.go
3
yaml.go
@ -343,6 +343,9 @@ func parseValue(argument string) interface{} {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
if argument == "[]" {
|
||||||
|
return make([]interface{}, 0)
|
||||||
|
}
|
||||||
return argument
|
return argument
|
||||||
}
|
}
|
||||||
return argument[1 : len(argument)-1]
|
return argument[1 : len(argument)-1]
|
||||||
|
Loading…
Reference in New Issue
Block a user