-
Notifications
You must be signed in to change notification settings - Fork 722
Add --yq option to limactl list and limactl info
#3998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
38a1f4a to
3d19d81
Compare
a0187a0 to
dcc3e31
Compare
The --yq option is only compatible with JSON or YAML output and will
apply the yq expression to the result before writing it to the output.
The following 2 commands are functionally identical (but may result in different
formatting, see below):
limactl ls default --yq .dir
limactl ls default --format json | limactl yq .dir
The output of `limactl list --json` will be pretty-printed when it goes
to a terminal. This means it is no longer one line per JSON object, but
has much improved legibility. Output to a file or pipe maintains JSON
Lines rules.
Also colorize the output of `limactl list`, `limactl info`, `limactl tmpl copy`,
and `limactl tmpl yq` if the output goes to the terminal.
Unfortunately the output of `yamlfmt` cannot be colorized, so the terminal
output may look slightly different from the output to a file or pipe (mostly
the extra indentation of list elements), but this seems like a reasonable
compromise.
Signed-off-by: Jan Dubois <[email protected]>
dcc3e31 to
02a2be1
Compare
|
Why not use |
❯ l ls default --format '{{.Config.User}}'
{0x14000a033e0 0x14000a033f0 0x14000a034d0 0x14000a03410 0x1400092fdd8}
❯ l ls default --yq .config.user
{
"name": "jan",
"comment": "Jan Dubois",
"home": "/home/jan.linux",
"shell": "/bin/bash",
"uid": 501
} |
|
And to elaborate on this a bit more, You have to know to look into https://github.com/lima-vm/lima/blob/master/pkg/limatype/lima_yaml.go to find out the Go internal structure. With I would consider the Go template format a legacy option that we added because we didn't have anything better yet. |
|
It does, but it is still obscure. How do you know the struct field is called It makes much more sense for the user to be able to use the same field name that is used in Why do they have to check the Lima source code to figure out how to write the template expression? |
|
Using ❯ l ls --yq 'select(.config.vmType == "vz").name'
bar
clone
default
❯ l ls --yq 'select(.config.vmType == "qemu").name'
qemu
❯ l ls --yq 'select(.status == "Running").name'
default
qemu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
|
Probably we should have bats tests |
They will come. I've been working on BATS tests; that how I found some of the issues with |
The
--yqoption is only compatible with JSON or YAML output and will apply the yq expression to the result before writing it to the output.The following 2 commands are functionally identical (but may result in different formatting, see below):
limactl ls default --yq .dir limactl ls default --format json | limactl yq .dirThe output of
limactl list --jsonwill be pretty-printed when it goes to a terminal. This means it is no longer one line per JSON object, but has much improved legibility. Output to a file or pipe maintains JSON Lines rules.Also colorize the output of
limactl list,limactl info,limactl tmpl copy, andlimactl tmpl yqif the output goes to the terminal.Unfortunately the output of
yamlfmtcannot be colorized, so the terminal output may look slightly different from the output to a file or pipe (mostly the extra indentation of list elements), but this seems like a reasonable compromise.Sample screenshot to show the difference:
The colors come from https://github.com/mikefarah/yq/blob/master/pkg/yqlib/color_print.go and are not configurable.