Skip to content

Recursively search for keys and apply custom sort #2279

Answered by mikefarah
jacobbednarz asked this question in Q&A
Discussion options

You must be logged in to vote

You've got the right idea with .. | select(has("methods")) - sounds like you were probably just missing brackets (and so it was expanding everything and then, separately, updating).

yq '(.. | select(has("methods")) | .methods) |= pick( (["get", "list", "create", "update", "delete"] + keys) | unique)' file.yaml

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jacobbednarz
Comment options

Answer selected by jacobbednarz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants