Skip to content
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

[Docs]: Please include trivial example for use of Format String #17676

Open
stellarpower opened this issue Mar 1, 2023 · 10 comments
Open

[Docs]: Please include trivial example for use of Format String #17676

stellarpower opened this issue Mar 1, 2023 · 10 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@stellarpower
Copy link
Contributor

stellarpower commented Mar 1, 2023

Feature request description

Please could the man pages for commands that include a format option include a very brief example of how these templates work? A single one-line "e.g. --format='{{.Name}}:{{.Tag}}'" in this section of the manual would do IMO. Options discussed below.

Not being a go user, the format {{.Tag}} is not obvious to me (looking like a half mix of JSON and liquid tags and with LeadingCamelCase - so a few things that I wouldn;t try off the top of my head all together), and as I have a really large graphroot on this machine, I wasted some amount of time sitting waiting for it to run, only having the string '.Tag' printed out to me many times!

Suggest potential solution

Options:

Man page sections on format flags:

  • have a quick example above or below the table of all supported template tags, or
  • link through to a more detailed page describing how the format argument works.

Have you considered any alternatives?

No response

Additional context

No response

@stellarpower stellarpower added the kind/feature Categorizes issue or PR as related to a new feature. label Mar 1, 2023
@stellarpower
Copy link
Contributor Author

Related: #17472

@rhatdan
Copy link
Member

rhatdan commented Mar 1, 2023

Interested in opening a PR with this change? We have examples in these man pages correct?

@Luap99
Copy link
Member

Luap99 commented Mar 1, 2023

Yes AFAIK we have examples at the bottom on most pages and also --help, but I agree that some docs actually describing how templates work would help, possibly just linking to the go docs, https://pkg.go.dev/text/template

Also FYI you use shell completion in templates to retrieve the names:

podman images --format {{.[TAB]
{{.Containers}}    {{.CreatedSince}}  {{.Digest}}        {{.ID}}            {{.IsReadOnly}}    {{.ParentId}}      {{.Repository}}    {{.Size}}          
{{.Created}}       {{.CreatedTime}}   {{.History}}       {{.ImageSummary.   {{.Labels.         {{.ReadOnly}}      {{.RepoTags}}      {{.Tag}}           
{{.CreatedAt}}     {{.Dangling}}      {{.Id}}            {{.IsDangling}}    {{.Names}}         {{.RepoDigests}}   {{.SharedSize}}    {{.VirtualSize}} 

@stellarpower
Copy link
Contributor Author

Thanks, yeah, only after opening this I saw it staring me in the face when I did podman images --help. Sure it's all in there, but being generally familiar with podman, the first place I would go to is the section documenting the particular flag (i.e. --format). I also ignored the overall help as it's a flag that applies across multiple commands, so was expecting it to be documented somewhere common or, expanded on in the options. The table is listed there and that's great, so I believe a quick example there just for reference on how it's used, and/or a full page on how it works with more sexy stuff you can do would be sensible. The --format flag is also where google landed me, multiple times, so in the end I had to search for how to do it in Docker to find some tutorial that worked it out. From memory this has happened a couple of times, hence opening this if others could benefit too.

Also interesting on the tab-completion. Although I'm on fish/nushell and don't get this (or any other tab completions usually, they tend to do more harm than good I find!) on either of those.

Conceptually happy to open a PR, except I'm super busy at the moment and am not really finding time ot follow up on anything am afraid ;)

@Luap99
Copy link
Member

Luap99 commented Mar 1, 2023

Tab completion should work on bash, zsh, fish and powershell assuming you have loaded the completion scripts, we use https://github.com/spf13/cobra to generate them. I tried it with fish and it seems to escape the closing brackets so it is not fully usable but still show the names:

podman images --format {{.Containers\}\} 
{{.Containers}}    {{.Created}}   {{.ID}}           {{.IsReadOnly}}  {{.ReadOnly}}     {{.SharedSize}} 
{{.CreatedAt}}     {{.Dangling}}  {{.Id}}           {{.Labels.       {{.RepoDigests}}  {{.Size}}       
{{.CreatedSince}}  {{.Digest}}    {{.ImageSummary.  {{.Names}}       {{.Repository}}   {{.Tag}}        
{{.CreatedTime}}   {{.History}}   {{.IsDangling}}   {{.ParentId}}    {{.RepoTags}}     {{.VirtualSize}}

So this is likely something that we should report to the cobra project.

@stellarpower
Copy link
Contributor Author

I wasn't getting anything but files in the PWD, but possibly my fish is not set up properly or a bit old. So I think that is a good idea.

@ibotty
Copy link
Contributor

ibotty commented Mar 9, 2023

The completion only triggers with podman images for me, not with podman inspect. Is that expected?

@Luap99
Copy link
Member

Luap99 commented Mar 9, 2023

Yes I excluded podman inspect because it accepts many different types (container, image, pod, network, volume) so it is not clear what to complete for this command.
podman container inspect or podman image inspect should work

@github-actions
Copy link

github-actions bot commented Apr 9, 2023

A friendly reminder that this issue had no activity for 30 days.

@rhatdan
Copy link
Member

rhatdan commented Apr 12, 2023

We believe this works in the current code base, closing. reopen if I am mistaken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

4 participants