Create limactl tmpl yq command to query a template#3313
Merged
AkihiroSuda merged 1 commit intolima-vm:masterfrom Mar 7, 2025
Merged
Create limactl tmpl yq command to query a template#3313AkihiroSuda merged 1 commit intolima-vm:masterfrom
limactl tmpl yq command to query a template#3313AkihiroSuda merged 1 commit intolima-vm:masterfrom
Conversation
2d9e9e3 to
f894b78
Compare
AkihiroSuda
reviewed
Mar 6, 2025
cmd/limactl/template.go
Outdated
| templateYQCommand := &cobra.Command{ | ||
| Use: "yq TEMPLATE EXPR", | ||
| Short: "Query template expressions", | ||
| Long: "Extract template data using a yq expression", |
Member
There was a problem hiding this comment.
Please add how this differs from the standalone yq command
Member
Author
There was a problem hiding this comment.
The only difference is that it works even when you don't have yq installed (e.g. on Windows GitHub runners). Not sure how you want to put this into the command help.
This is essentially the same as the gh api ... --jq option, having the tool already built in, so you don't need to worry about having it installed.
I'm planning to eventually add --yq options to limactl ls and limactl info as well, but not right now.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Member
Author
There was a problem hiding this comment.
I've updated the PR to produce the following output:
❯ limactl tmpl yq --help
Use the builtin YQ evaluator to extract information from a template.
External references are embedded and default values are filled in
before the YQ expression is evaluated.
Example:
limactl template yq template://default '.images[].location'
The example command is equivalent to using an external yq command like this:
limactl template copy --fill template://default - | yq '.images[].location'
Usage:
limactl template yq TEMPLATE EXPR [flags]
...664f54a to
955d852
Compare
The following commands are equivalent: limactl tmpl yq $TEMPLATE $EXPRESSION limactl tmpl copy --fill $TEMPLATE - | yq $EXPRESSION The new `yq` variant is clearer, but more importantly does not require that `yq` is installed. Since we already include all the code in limactl anyways, we get this functionality almost for free. Signed-off-by: Jan Dubois <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The following commands are equivalent:
The new
yqvariant is clearer, but more importantly does not require thatyqis installed. Since we already include all the code in limactl anyways, we get this functionality almost for free1.Example:
Footnotes
10 lines for the Cobra definition and 20 lines for the implementation; the rest is just refactoring. ↩