cobra
cobra copied to clipboard
Fix zsh completion for commands which output is influenced by the permissions it is run with.
This PR originates from when using nerdctl
(which built its CLI with cobra), the auto-completion will not work for unprivileged users, even if they have sudo permission and are trying to tab out the command with sudo
prefix.
For example, sudo nerdctl <tab>
will fallback to file completion. That is because the hidden nerdctl __complete ""
is run without sudo permission under the hood and fails.
This patch will enable the correct permission to be passed to the underlying hidden __complete
command, thus correctly handling the case for commands which output is influenced by the permissions it is run with.
Currently, this fix is only available to zsh. And I have put it behind a switch that defaults to false.
Before
$ sudo nerdctl
completing filename
file1 file2 image1
After
$ sudo nerdctl
completing completions
apparmor -- Manage AppArmor profiles
attach -- Attach stdin, stdout, and stderr to a running container.
build -- Build an image from a Dockerfile. Needs buildkitd to be runni
builder -- Manage builds
...
$ nerdctl
completing filename
file1 file2 image1