mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 05:38:04 +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) {
|
||||
var parsedData yaml.MapSlice
|
||||
var parsedData interface{}
|
||||
var deletePath string
|
||||
|
||||
if len(args) < 2 {
|
||||
@ -372,17 +372,11 @@ func deleteYaml(args []string) (interface{}, error) {
|
||||
deletePath = args[1]
|
||||
|
||||
if err := readData(args[0], 0, &parsedData); err != nil {
|
||||
var generalData interface{}
|
||||
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
|
||||
return nil, err
|
||||
}
|
||||
|
||||
path := parsePath(deletePath)
|
||||
return deleteMap(parsedData, path), nil
|
||||
paths := parsePath(deletePath)
|
||||
return deleteChildValue(parsedData, paths), nil
|
||||
}
|
||||
|
||||
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}]]}]}]",
|
||||
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