Skip to content

Search and Replace: Support advanced path expressions#1225

Merged
phanimarupaka merged 1 commit intokptdev:masterfrom
phanimarupaka:PathExpressionsContd
Nov 19, 2020
Merged

Search and Replace: Support advanced path expressions#1225
phanimarupaka merged 1 commit intokptdev:masterfrom
phanimarupaka:PathExpressionsContd

Conversation

@phanimarupaka
Copy link
Copy Markdown
Contributor

@mortent

This PR supports more path expressions for search and replace.

@phanimarupaka phanimarupaka changed the title Support advanced path expressions Search and Replace: Support advanced path expressions Nov 17, 2020
Comment thread go.mod Outdated
Comment thread internal/util/search/pathparser.go
name: "search by array objects path",
args: []string{"--by-path", "spec.foo[1].c"},
name: "search replace by array path regex",
args: []string{"--by-path", "spec.foo[1]", "--put-literal", "c"},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the provided number is outside the bounds of the array?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a no match. Similar to providing non-existing path. We will support appending elements to arrays in future. https://mikefarah.gitbook.io/yq/usage/path-expressions#appending-to-arrays

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like something that would be worthy of testing. This also includes the use of negative indexes (as described in the link) if that is something that we support.

Copy link
Copy Markdown
Contributor Author

@phanimarupaka phanimarupaka Nov 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mortent Added a test case. We may add more features based on the requirements in future. yq supports negative indices but for us it depends on use-cases we might encounter in the future.

@phanimarupaka phanimarupaka merged commit 6de8ff4 into kptdev:master Nov 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants