1
0
mirror of https://github.com/taigrr/yq synced 2025-01-18 04:53:17 -08:00

Fixed delete array pattern matching

This commit is contained in:
Mike Farah
2020-01-30 14:55:58 +11:00
parent 789ea02096
commit 44f36833cf
4 changed files with 41 additions and 15 deletions

View File

@@ -1255,7 +1255,7 @@ b:
test.AssertResult(t, expectedOutput, result.Output)
}
func TestDeleteYamlArray(t *testing.T) {
func TestDeleteYamlArrayCmd(t *testing.T) {
content := `- 1
- 2
- 3
@@ -1275,6 +1275,26 @@ func TestDeleteYamlArray(t *testing.T) {
test.AssertResult(t, expectedOutput, result.Output)
}
func TestDeleteYamlArrayExpressionCmd(t *testing.T) {
content := `- name: fred
- name: cat
- name: thing
`
filename := test.WriteTempYamlFile(content)
defer test.RemoveTempYamlFile(filename)
cmd := getRootCommand()
result := test.RunCmd(cmd, fmt.Sprintf("delete %s (name==cat)", filename))
if result.Error != nil {
t.Error(result.Error)
}
expectedOutput := `- name: fred
- name: thing
`
test.AssertResult(t, expectedOutput, result.Output)
}
func TestDeleteYamlMulti(t *testing.T) {
content := `apples: great
---

View File

@@ -10,7 +10,7 @@ func createDeleteCmd() *cobra.Command {
var cmdDelete = &cobra.Command{
Use: "delete [yaml_file] [path_expression]",
Aliases: []string{"d"},
Short: "yq d [--inplace/-i] [--doc/-d index] sample.yaml 'b.e(name==fred).value'",
Short: "yq d [--inplace/-i] [--doc/-d index] sample.yaml 'b.e(name==fred)'",
Example: `
yq delete things.yaml 'a.b.c'
yq delete things.yaml 'a.*.c'