-
Notifications
You must be signed in to change notification settings - Fork 585
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
Implement custom go format for list command #324
Conversation
I'm wondering what the use-case for this is. At first I expected the output to still have proper column format etc, but that is of course not possible when using generic go templates (maybe we should also have a I think for this particular PR the To be useful there needs to be a way to list all available template variables, either as part of One use case I could think off was creating an Anyways, I would still like to understand how this feature is expected to be used. |
There were similar functions for The alternative was doing something like |
You can do that with "grep" now, but yes that would be nice too. |
I think Podman made up some home-grown $ podman machine ls --format 'table {{ .Name }} {{.Default}}'
NAME DEFAULT
podman-machine-default* true |
Ok, thats fine. I thought for $ kubectl get pods -A -o custom-columns='NAME:.metadata.name,IMAGES:spec.containers[*].image'
NAME IMAGES
helm-install-traefik-8569p rancher/klipper-helm:v0.3.0
svclb-traefik-tmz9l rancher/klipper-lb:v0.1.2,rancher/klipper-lb:v0.1.2
traefik-5dd496474-87cbj rancher/library-traefik:1.7.19
coredns-66c464876b-xrcbn rancher/coredns-coredns:1.6.9
local-path-provisioner-7ff9579c6-8tnvq rancher/local-path-provisioner:v0.0.14
metrics-server-7b4f8b595-whrjs rancher/metrics-server:v0.3.6
builder-4fl6p docker.io/moby/buildkit:v0.8.3,rancher/kim:v0.1.0-beta.6 |
The
|
It does. I thought you could write: I don't understand how the
Anyways, extending the tabular output seems independent of the goal of this PR, so should be out of scope. Sorry for hi-jacking the discussion. |
minikube has some weird "fences" between columns
In the old days, we just used tabs or something and then piped into a post processor |
Sorry for derailing the PR with the extended discussion. What I would like to see for this PR is that I would also like to see As for #322 I would prefer to not add global constants into the @@ -74,7 +77,16 @@ func listAction(cmd *cobra.Command, args []string) error {
logrus.WithError(err).Errorf("instance %q does not exist?", instName)
continue
}
- err = tmpl.Execute(cmd.OutOrStdout(), inst)
+ var data struct {
+ store.Instance
+ LimaHome string
+ IdentityFile string
+ }
+ configDir, _ := dirnames.LimaConfigDir()
+ data.Instance = *inst
+ data.LimaHome, _ = dirnames.LimaDir()
+ data.IdentityFile = filepath.Join(configDir, filenames.UserPrivateKey)
+ err = tmpl.Execute(cmd.OutOrStdout(), data)
if err != nil {
return err
} This provides the desired functionality without duplicating the global data into each instance struct: $ l ls --format '{{.Name}} {{.LimaHome}} {{.IdentityFile}}'
aarch64 /Users/jan/.lima /Users/jan/.lima/_config/user
alpine /Users/jan/.lima /Users/jan/.lima/_config/user
colima /Users/jan/.lima /Users/jan/.lima/_config/user
default /Users/jan/.lima /Users/jan/.lima/_config/user This can be included in this PR, or could be a separate one as well. |
Here is the $ function halog { tail -f "$(limactl ls -f ""{{.LimaHome}}/{{.Name}}/ha.stderr.log"" | grep ${1:-default})"; }
$ halog
[...]
{"level":"info","msg":"Sending QMP system_powerdown command","time":"2021-10-12T20:31:45-07:00"}
{"error":null,"level":"info","msg":"QEMU has exited","time":"2021-10-12T20:31:46-07:00"}
^C
$ halog alpine
[...]
{"level":"info","msg":"Not forwarding TCP [::]:22","time":"2021-10-07T19:11:48-07:00"}
{"level":"info","msg":"Not forwarding TCP 0.0.0.0:22","time":"2021-10-07T19:11:48-07:00"}
^C Still would be better if the PS: I realize this function is interesting only when you use different shells with different |
71e50b9
to
0331c03
Compare
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
0331c03
to
4f042c4
Compare
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.
LGTM, although I have a slight preference to have --list-fields
return them in sorted order. Maybe you can still update?
Not going to merge in case @AkihiroSuda has further feedback.
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
Closes #318