mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-23 22:25:42 +00:00
Fixed delete command for arrays
This commit is contained in:
parent
297522cbdd
commit
1b22e1d812
14
yq.go
14
yq.go
@ -362,7 +362,7 @@ func deleteProperty(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func deleteYaml(args []string) (interface{}, error) {
|
func deleteYaml(args []string) (interface{}, error) {
|
||||||
var parsedData yaml.MapSlice
|
var parsedData interface{}
|
||||||
var deletePath string
|
var deletePath string
|
||||||
|
|
||||||
if len(args) < 2 {
|
if len(args) < 2 {
|
||||||
@ -372,17 +372,11 @@ func deleteYaml(args []string) (interface{}, error) {
|
|||||||
deletePath = args[1]
|
deletePath = args[1]
|
||||||
|
|
||||||
if err := readData(args[0], 0, &parsedData); err != nil {
|
if err := readData(args[0], 0, &parsedData); err != nil {
|
||||||
var generalData interface{}
|
return nil, err
|
||||||
if err = readData(args[0], 0, &generalData); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
item := yaml.MapItem{Key: "thing", Value: generalData}
|
|
||||||
parsedData = yaml.MapSlice{item}
|
|
||||||
deletePath = "thing." + deletePath
|
|
||||||
}
|
}
|
||||||
|
|
||||||
path := parsePath(deletePath)
|
paths := parsePath(deletePath)
|
||||||
return deleteMap(parsedData, path), nil
|
return deleteChildValue(parsedData, paths), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergeProperties(cmd *cobra.Command, args []string) error {
|
func mergeProperties(cmd *cobra.Command, args []string) error {
|
||||||
|
@ -106,3 +106,11 @@ func TestDeleteYaml(t *testing.T) {
|
|||||||
"[{a Easy! as one two three} {b [{d [3 4]} {e [[{name fred} {value 3}] [{name sam} {value 4}]]}]}]",
|
"[{a Easy! as one two three} {b [{d [3 4]} {e [[{name fred} {value 3}] [{name sam} {value 4}]]}]}]",
|
||||||
formattedResult)
|
formattedResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDeleteYamlArray(t *testing.T) {
|
||||||
|
result, _ := deleteYaml([]string{"examples/sample_array.yaml", "[1]"})
|
||||||
|
formattedResult := fmt.Sprintf("%v", result)
|
||||||
|
assertResult(t,
|
||||||
|
"[1 3]",
|
||||||
|
formattedResult)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user