-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[RFE]: --format go template fields documentation #17472
Comments
A friendly reminder that this issue had no activity for 30 days. |
@Luap99 Is this still an open issue? Most of these are documented now. Just need a way to test for missing documents. |
This is still very much an issue:
Plus, this issue is about much more: as I read it, it's about autodocumenting (not just validating) and it includes the possibility of really getting rid of the unwanted options. |
A friendly reminder that this issue had no activity for 30 days. |
I think the actual data returned depend on the underlying data structure (image, container, etc.) that should be defined somewhere else. But I came here looking for go functions available in the templates. For example, I can do this now: $ podman container inspect --format '{{range $i, $env := .Config.Env}}{{ println $env }}{{ end }}' $container
PATH=/me/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
TERM=xterm
container=podman
HOME=/me
HOSTNAME=9402498241ff I can filter on the exact value: $ podman container inspect --format '{{range $i, $env := .Config.Env}}{{ if eq $env "HOME=/me" }}{{ $env }}{{ end }}{{ end }}' $container
HOME=/me but I do not seem to be able to search on a substring or invoke anything more complicated than a simple (I do not understand how |
@saper This issue is explicitly about generating the field doc description based on the actual structs used and not for general docs on how to use the template syntax. For that there is already #17676 so please follow that. Templates are limited to some extend and you cannot just call arbitrary functions in it. If you need more logic I suggest you use shell script. |
@Luap99 thanks for the pointer, I'll ask there. |
/kind feature
This is an continuation of my comment in #17443 (comment)
Problem statement
I think we can all agree that most --format field names should be documented. @edsantiago did some great progress with his PR. However I see some problems with that approach as mentioned in the comment.
The main concern is around differences between docs and auto completion, right now the auto completion shows a bit to much, some nested internal struct are exposed which means that changing them can causes breaking changes to templates. Thus we do want them documented but also not shown on auto complete.
Also the current approach requires somebody to add descriptives comments for each field in the docs. This can be a lot of work. Most fields are actually already commented reasonably well via standard go docs in the code so there is a lot of copy paste involved.
Proposed solution
With this in mind I propose we need a custom tool that can write us the docs bases on our code comments. Go has strong AST parsing libraries (https://pkg.go.dev/golang.org/x/tools/go/packages and https://pkg.go.dev/go/ast) that can do the heavy lifting.
The way I image it working is to first search for all
common.AutocompleteFormat(...)
calls, this what the completion logic is based on. Then we can search the ast for our type that was given as argument, this struct contains all fields that can be used in the template (only exported ones are used). From there we can read each field and the go comment attached to it. This must happen recursively for all structs within this struct and also work for embedded structs.To make field not show up it should be private or if that is not possible I suggest we add a new field tag called
completion:"none"
:The reason we use a tag and not a comment is because the completion code which uses reflect can read tags but not comment at runtime. This allows us to keep them hidden in docs and completion so they are always in sync without extra work.
Once we have the info we will then write it the stdout or file in the same tabular format that is used and the moment in the man pages.
The man page validation script can then use this to diff against the man page, I am also open to different formats when it should make things simpler to compare.
Possible problems
The text was updated successfully, but these errors were encountered: