-
Notifications
You must be signed in to change notification settings - Fork 886
[WIP] autogenerate bash completions #1500
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
|
Should we just remove the bash completions and always generate them? |
I'm ok with that, it's just that I noticed podman's completions were included in the source itself. |
|
I'm guessing it's ok to document the completion command? Anyone think otherwise? |
|
Also, do we need zsh and fish while we're at it? I noticed the installation only mentioned bash. |
a0c6f72 to
a96293f
Compare
Generates bash completion. Fixes: containers#1264 Signed-off-by: Lokesh Mandvekar <[email protected]>
Signed-off-by: Lokesh Mandvekar <[email protected]>
|
The current |
Signed-off-by: Lokesh Mandvekar <[email protected]>
Signed-off-by: Lokesh Mandvekar <[email protected]>
|
@Luap99 PTAL |
|
I still need to resolve: @edsantiago thoughts? |
Signed-off-by: Lokesh Mandvekar <[email protected]>
|
I would suggest making |
are there any issues to exposing the completion subcommand to users? |
|
Podman hides it |
|
i gotta rework this to hide the completion subcommand. |
mtrmac
left a comment
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!
Should we just remove the bash completions and always generate them?
I’d weakly prefer that; we must not change the generated code, and we are not going to realistically review it in detail.
AFAICS the cost of having the committed in the repo would be to add extra tasks and extra churn on possible re-vendors of the CLI library (and extra worry about getting that right so that the file doesn’t accidentally get stale) — at the benefit of possibly making cross-architecture builds a bit easier, if anyone ever does that.
Also, do we need zsh and fish while we're at it? I noticed the installation only mentioned bash.
We do need zsh (the default shell on macOS). I have no idea how widespread or relevant fish is.
After this infrastructure, the more interesting (?) part is making the completions good/magical.
Notably the manually-written script seems to be able to suggest transport names; preserving that in this PR (for the relevant arguments only?) would be very nice.
Any other additions, like perfecting completion for all the argument values, with everything https://github.com/spf13/cobra/blob/master/shell_completions.md allows, probably should be separate PRs later.
| GOOS=$(word 2,$(subst ., ,$@)) GOARCH=$(word 3,$(subst ., ,$@)) $(GO) build $(MOD_VENDOR) ${SKOPEO_LDFLAGS} -tags "containers_image_openpgp $(BUILDTAGS)" -o $@ ./cmd/skopeo | ||
| local-cross: bin/skopeo.darwin.amd64 bin/skopeo.linux.arm bin/skopeo.linux.arm64 bin/skopeo.windows.386.exe bin/skopeo.windows.amd64.exe | ||
|
|
||
| .PHONY: bash-completions |
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.
Why should any of these be .PHONY dependencies? AFAICS the target is a real file that depends only on a real file.
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.
ack, noted.
| install-fish-completions: | ||
| install -m 755 -d $(DESTDIR)$(FISHCOMPLETIONSDIR) | ||
| install -m 644 completions/fish/skopeo.fish $(DESTDIR)$(FISHCOMPLETIONSDIR) | ||
|
|
||
| install-zsh-completions: | ||
| install -m 755 -d $(DESTDIR)$(ZSHCOMPLETIONSDIR) | ||
| install -m 644 completions/zsh/_skopeo $(DESTDIR)$(ZSHCOMPLETIONSDIR) |
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.
It seems simpler to just install all of them in install-completions. Who has so little space and so much time to choose individually?
|
The reason the completion command is hidden in podman is because I did not want Either way you should document this command in a man page. Your current page has not much information on how to use this command. I recommend to copy and adapt the podman page: https://github.com/containers/podman/blob/main/docs/source/markdown/podman-completion.1.md Also right now you are using the default included completion command. This has some problems: To fix these issues I would recommend you to use the same command structure as in podman: https://github.com/containers/podman/blob/main/cmd/podman/completion/completion.go It would be great if we could have consistency with that. IF you want to use that I think we should add this command to c/common here https://github.com/containers/common/tree/main/pkg/completion and then import it into podman/skopeo.
Yes please enable all shells. Having this enabled for the other shell requires exactly zero additional maintenance. That is the beauty with the cobra completion logic in golang.
This is the difficult and tedious part. Basically every command and flag will need a ValidArgsFunction to provide customized completion. The current default in skopeo is to provide no completion for flags and commands besides the transpart name completion AFAIK. With this change we get the default shell completion (e.g. path names will get completed). This makes sense for some flags This took a very long time in podman but was definitely worth it. There is also a test to ensure every command and flag has such function set https://github.com/containers/podman/blob/main/cmd/podman/shell_completion_test.go I do not think this is required for this PR but I aggre with @mtrmac that we should try to preserve the current behaviour (complete transport names and maybe more?) to not cause regression for users. |
|
FYI This is the PR for podman containers/podman#6442 |
|
I agree the command should be hidden. We don't want general users playing with it. |
I am not familiar with all the shells, but at least the Pointers for how to enable the bash-completion package in general are useful, and might be in a man page, sure, but it’s not completely obvious to me that those not-really-Skopeo-instructions about bash-completion, and a reference documentation for a hidden command that users should never need to call manually, should be in the same document.
My first impression is that making that an exception in the checker (or hiding the command entirely, which we want to do anyway I think, and having the checker ignore it by general rule) would be simpler, and would make it easier to benefit from any possible future improvements to the built-in command. I.e. the train of thought is that if we don’t place useful information in a man page for that subcommand, we don’t need to manage what that subcommand looks like in a man page, and so we don’t need special code to implement that subcommand. I like both the starting and ending point :) but I could well be missing something. |
|
A friendly reminder that this PR had no activity for 30 days. |
|
@lsm5 What is going on with this PR? |
https://github.com/spf13/cobra 1.3.0 now provides rootCmd.CompletionOptions.HiddenDefaultCmd = true |
|
I would like to take this over and push it over the finish line. I already created containers/common#1043 so that podman, skopeo and buildah could share the same completion command. |
|
@Luap99 yes, please go ahead. Thanks a lot! |
|
Actually, the other PR was just merged, I’m afraid I have forgotten to close this one. |
Signed-off-by: Lokesh Mandvekar [email protected]