Repository navigation
cmd: Added shell completion command - #840
Conversation
|
Build succeeded.
|
|
This looks like a great start and works nicely for general options. Here are some suggestions for next steps:
|
|
I was working on that today. I'm fixing some bits here and there and will update the branch. About the generated bash and rpm install, I will work on that after I get the completion feature finished. |
|
Build failed.
|
| var image_names []string | ||
| if images, err := getImages(); err == nil { | ||
| for _, image := range images { | ||
| image_names = append(image_names, image.Names[0]) |
There was a problem hiding this comment.
Be careful here because image.Names may not contain a single string. See #800.
e128791 to
2a1666b
Compare
|
Build succeeded.
|
Cobra (the CLI library) has an advanced support for generating shell completion. It support Bash, Zsh, Fish and PowerShell. This offering covers the majority of use cases with some exceptions, of course. The generated completion scripts have one behavioral difference when compared to the existing solution: flags (--xxx) are not shown by default. User needs to type '-' first to get the completion. containers#840
The previous commit added a means to generating the completion scripts and this one plugs that into the build system. A new build option 'install_completions' has been introduced. Completions for bash and fish use pkg-config for getting the preferred install locations for the completions. If the packages are not available, fallbacks are in-place. The 'completion' subdir has been kept to work around the ideology of Meson that does not allow creating/outputing files in subdirectories nor using the output of custom_target() in install_data(). containers#840
2a1666b to
e4e4783
Compare
|
I rebased this on top of #917 to benefit from the work on updating dependencies (required for the Cobra features this PR makes use of). |
|
This should be good for testing. @debarshiray @olivergs @travier 🙏 |
|
Build failed.
|
Cobra (the CLI library) has an advanced support for generating shell completion. It support Bash, Zsh, Fish and PowerShell. This offering covers the majority of use cases with some exceptions, of course. The generated completion scripts have one behavioral difference when compared to the existing solution: flags (--xxx) are not shown by default. User needs to type '-' first to get the completion. containers#840 Co-authored-by: Ondřej Míchal <[email protected]>
The previous commit added a means to generating the completion scripts and this one plugs that into the build system. A new build option 'install_completions' has been introduced. Completions for bash and fish use pkg-config for getting the preferred install locations for the completions. If the packages are not available, fallbacks are in-place. The 'completion' subdir has been kept to work around the ideology of Meson that does not allow creating/outputing files in subdirectories nor using the output of custom_target() in install_data(). containers#840
e4e4783 to
1b6b9c2
Compare
|
Merge Failed. This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset. |
Cobra (the CLI library) has an advanced support for generating shell completion. It support Bash, Zsh, Fish and PowerShell. This offering covers the majority of use cases with some exceptions, of course. The generated completion scripts have one behavioral difference when compared to the existing solution: flags (--xxx) are not shown by default. User needs to type '-' first to get the completion. containers#840 Co-authored-by: Ondřej Míchal <[email protected]>
The previous commit added a means to generating the completion scripts and this one plugs that into the build system. A new build option 'install_completions' has been introduced. Completions for bash and fish use pkg-config for getting the preferred install locations for the completions. If the packages are not available, fallbacks are in-place. The 'completion' subdir has been kept to work around the ideology of Meson that does not allow creating/outputing files in subdirectories nor using the output of custom_target() in install_data(). containers#840
1b6b9c2 to
47eb18a
Compare
|
Darn you Zuul! This works locally :/. |
|
Build failed.
|
|
I gave it a try today by doing: but as far as I could see, the comments from #840 (comment) still apply. This is however still progress as at least the commands are completed so addressing my comments could be for a later PR. Thanks! |
Which part of the comment do you mean? If the "extra completion" then could you elaborate a bit more? I don't quite understand the suggestion in its current form. The later part should be taken care of at build (resp. install) time. The completion is generated using the build system.
Also thanks! |
|
Yes, it's about the extra completion. Being able to type |
While the use of Logrus is convenient, it causes unneeded fluff to be printed during a panic which distracts from finding the cause of the panic in the first place. Fallout from containers#840
Requiring having a shell installed at build-time to get the appropriate location won't cover the cases like when a system has such a location set to a non-standard path. The use of fallbacks together with hardcoded paths also increases the complexity of this particular feature. All 3 major shells (Bash, Zsh, Fish) have documented default directories where they look for completion scripts and we can make use of that. Additionaly, hard-coding of these paths seems to be the standard among projects. Fallout from containers#840 containers#1055
We don't provide completion for PowerShell, we support only Linux and instructions for loading completion files are redundant in Toolbx. Fallout from containers#840 containers#1055
V1 is legacy since v1.2.0[0]. [0] https://github.com/spf13/cobra/releases/tag/v1.2.0 Fallout from containers#840 containers#1055
While the use of Logrus is convenient, it causes unneeded fluff to be printed during a panic which distracts from finding the cause of the panic in the first place. Fallout from containers#840 containers#1055
|
Opened #1055 to address the raised concerns. |
Requiring having a shell installed at build-time to get the appropriate location won't cover the cases like when a system has such a location set to a non-standard path. The use of fallbacks together with hardcoded paths also increases the complexity of this particular feature. All 3 major shells (Bash, Zsh, Fish) have documented default directories where they look for completion scripts and we can make use of that. Additionaly, hard-coding of these paths seems to be the standard among projects. Fallout from containers#840 containers#1055
We don't provide completion for PowerShell, we support only Linux and instructions for loading completion files are redundant in Toolbx. Fallout from containers#840 containers#1055
V1 is legacy since v1.2.0[0]. [0] https://github.com/spf13/cobra/releases/tag/v1.2.0 Fallout from containers#840 containers#1055
While the use of Logrus is convenient, it causes unneeded fluff to be printed during a panic which distracts from finding the cause of the panic in the first place. Fallout from containers#840 containers#1055
This is particularly relevant for Z shell, because, unlike Bash's
bash-completion.pc and fish's fish.pc, it doesn't have an API to detect
the location for the shell completions and Debian and Fedora use
different locations [1, 2]. Namely, /usr/share/zsh/vendor-completions
and /usr/share/zsh/site-functions.
An option to specify the locations for the shell completions can
optimize the build if there's an alternate API for the location that
doesn't involve using bash-completion.pc and fish.pc as build
dependencies. eg., Fedora provides the _tmpfilesdir RPM macro to
specify the location for vendor-supplied tmpfiles.d(5) files, which
makes it possible to avoid having systemd as a build dependency [3].
Finally, when installing to a non-system-wide prefix while hacking on
Toolbox as a non-root user, the locations for the completions in the
shells' APIs might not be accessible. Being able to override the
locations prevents the installation from failing.
[1] Debian zsh commit bf0a44a8744469b5
https://salsa.debian.org/debian/zsh/-/commit/bf0a44a8744469b5
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=620452
[2] https://src.fedoraproject.org/rpms/zsh/blob/f37/f/zsh.spec
[3] Fedora toolbox commit 9bebde5bb60f36e3
https://src.fedoraproject.org/rpms/toolbox/c/9bebde5bb60f36e3
containers#840
There's no well-defined use-case for having a build option for generating and installing the shell completions. The bash-completion and fish dependencies are already optional, and there's no dependency required for Z shell. The shell completions for Bash and fish won't be generated and installed if they are absent. So the build option isn't reducing the dependency burden. The build option is a way to disable the generation and installation of the shell completions, regardless of whether the necessary dependencies are present or not. There's no well-defined use-case for that. Fallout from bafbbe8 containers#1123 containers#840
This is particularly relevant for Z shell, because, unlike Bash's
bash-completion.pc and fish's fish.pc, it doesn't have an API to detect
the location for the shell completions and Debian and Fedora use
different locations [1, 2]. Namely, /usr/share/zsh/vendor-completions
and /usr/share/zsh/site-functions.
An option to specify the locations for the shell completions can
optimize the build if there's an alternate API for the location that
doesn't involve using bash-completion.pc and fish.pc as build
dependencies. eg., Fedora provides the _tmpfilesdir RPM macro to
specify the location for vendor-supplied tmpfiles.d(5) files, which
makes it possible to avoid having systemd as a build dependency [3].
Finally, when installing to a non-system-wide prefix while hacking on
Toolbox as a non-root user, the locations for the completions in the
shells' APIs might not be accessible. Being able to override the
locations prevents the installation from failing.
[1] Debian zsh commit bf0a44a8744469b5
https://salsa.debian.org/debian/zsh/-/commit/bf0a44a8744469b5
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=620452
[2] https://src.fedoraproject.org/rpms/zsh/blob/f37/f/zsh.spec
[3] Fedora toolbox commit 9bebde5bb60f36e3
https://src.fedoraproject.org/rpms/toolbox/c/9bebde5bb60f36e3
containers#1123
containers#840
The bash-completion and fish dependencies are already optional, and there's no dependency required for Z shell. The shell completions for Bash and fish won't be generated and installed if they are absent. So the build option isn't reducing the dependency burden. The build option is a way to disable the generation and installation of the shell completions, regardless of whether the necessary dependencies are present or not. The only use-case for this is when installing to a non-system-wide prefix while hacking on Toolbox as a non-root user, because the locations for the completions in the shells' APIs might not be accessible. Being able to disable the completions prevents the installation from failing. Fallout from bafbbe8 containers#1123 containers#840 build: Add options to override the locations for the shell completions This is particularly relevant for Z shell, because, unlike Bash's bash-completion.pc and fish's fish.pc, it doesn't have an API to detect the location for the shell completions and Debian and Fedora use different locations [1, 2]. Namely, /usr/share/zsh/vendor-completions and /usr/share/zsh/site-functions. An option to specify the locations for the shell completions can optimize the build if there's an alternate API for the location that doesn't involve using bash-completion.pc and fish.pc as build dependencies. eg., Fedora provides the _tmpfilesdir RPM macro to specify the location for vendor-supplied tmpfiles.d(5) files, which makes it possible to avoid having systemd as a build dependency [3]. Finally, when installing to a non-system-wide prefix while hacking on Toolbox as a non-root user, the locations for the completions in the shells' APIs might not be accessible. Being able to override the locations prevents the installation from failing. [1] Debian zsh commit bf0a44a8744469b5 https://salsa.debian.org/debian/zsh/-/commit/bf0a44a8744469b5 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=620452 [2] https://src.fedoraproject.org/rpms/zsh/blob/f37/f/zsh.spec [3] Fedora toolbox commit 9bebde5bb60f36e3 https://src.fedoraproject.org/rpms/toolbox/c/9bebde5bb60f36e3 containers#1123 containers#840
The bash-completion and fish dependencies were already optional - the shell completions for Bash and fish won't be generated and installed if they are absent; and there's no dependency required for Z shell. So the install_completions build option wasn't reducing the dependency burden. The build option was a way to disable the generation and installation of the shell completions, regardless of whether the necessary dependencies are present or not. The only use-case for this is when installing to a non-system-wide prefix while hacking on Toolbox as a non-root user, because the locations for the completions advertised by the shells' APIs might not be accessible. Being able to disable the completions prevents the installation from failing. A different way of ensuring a smooth developer experience for a Toolbx hacker is to offer a way to change the locations where the shell completions are installed, which is necessary and beneficial for other use-cases. Z shell, unlike Bash's bash-completion.pc and fish's fish.pc, doesn't offer an API to detect the location for the shell completions. This means that Debian and Fedora use different locations [1, 2]. Namely, /usr/share/zsh/vendor-completions and /usr/share/zsh/site-functions. An option to specify the locations for the shell completions can optimize the build, if there's an alternate API for the location that doesn't involve using bash-completion.pc and fish.pc as build dependencies. eg., Fedora provides the _tmpfilesdir RPM macro to specify the location for vendor-supplied tmpfiles.d(5) files, which makes it possible to avoid having systemd.pc as a build dependency [3]. Fallout from bafbbe8 [1] Debian zsh commit bf0a44a8744469b5 https://salsa.debian.org/debian/zsh/-/commit/bf0a44a8744469b5 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=620452 [2] https://src.fedoraproject.org/rpms/zsh/blob/f37/f/zsh.spec [3] Fedora toolbox commit 9bebde5bb60f36e3 https://src.fedoraproject.org/rpms/toolbox/c/9bebde5bb60f36e3 containers#1123 containers#840
The bash-completion and fish dependencies were already optional - the shell completions for Bash and fish won't be generated and installed if they are absent; and there's no dependency required for Z shell. So the install_completions build option wasn't reducing the dependency burden. The build option was a way to disable the generation and installation of the shell completions, regardless of whether the necessary dependencies are present or not. The only use-case for this is when installing to a non-system-wide prefix while hacking on Toolbox as a non-root user, because the locations for the completions advertised by the shells' APIs might not be accessible. Being able to disable the completions prevents the installation from failing. A different way of ensuring a smooth developer experience for a Toolbx hacker is to offer a way to change the locations where the shell completions are installed, which is necessary and beneficial for other use-cases. Z shell, unlike Bash's bash-completion.pc and fish's fish.pc, doesn't offer an API to detect the location for the shell completions. This means that Debian and Fedora use different locations [1, 2]. Namely, /usr/share/zsh/vendor-completions and /usr/share/zsh/site-functions. An option to specify the locations for the shell completions can optimize the build, if there's an alternate API for the location that doesn't involve using bash-completion.pc and fish.pc as build dependencies. eg., Fedora provides the _tmpfilesdir RPM macro to specify the location for vendor-supplied tmpfiles.d(5) files, which makes it possible to avoid having systemd.pc as a build dependency [3]. Fallout from bafbbe8 [1] Debian zsh commit bf0a44a8744469b5 https://salsa.debian.org/debian/zsh/-/commit/bf0a44a8744469b5 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=620452 [2] https://src.fedoraproject.org/rpms/zsh/blob/f37/f/zsh.spec [3] Fedora toolbox commit 9bebde5bb60f36e3 https://src.fedoraproject.org/rpms/toolbox/c/9bebde5bb60f36e3 containers#1123 containers#840
The bash-completion and fish dependencies were already optional - the shell completions for Bash and fish won't be generated and installed if they are absent; and there's no dependency required for Z shell. So the install_completions build option wasn't reducing the dependency burden. The build option was a way to disable the generation and installation of the shell completions, regardless of whether the necessary dependencies are present or not. The only use-case for this is when installing to a non-system-wide prefix while hacking on Toolbox as a non-root user, because the locations for the completions advertised by the shells' APIs might not be accessible. Being able to disable the completions prevents the installation from failing. A different way of ensuring a smooth developer experience for a Toolbx hacker is to offer a way to change the locations where the shell completions are installed, which is necessary and beneficial for other use-cases. Z shell, unlike Bash's bash-completion.pc and fish's fish.pc, doesn't offer an API to detect the location for the shell completions. This means that Debian and Fedora use different locations [1, 2]. Namely, /usr/share/zsh/vendor-completions and /usr/share/zsh/site-functions. An option to specify the locations for the shell completions can optimize the build, if there's an alternate API for the location that doesn't involve using bash-completion.pc and fish.pc as build dependencies. eg., Fedora provides the _tmpfilesdir RPM macro to specify the location for vendor-supplied tmpfiles.d(5) files, which makes it possible to avoid having systemd.pc as a build dependency [3]. Fallout from bafbbe8 [1] Debian zsh commit bf0a44a8744469b5 https://salsa.debian.org/debian/zsh/-/commit/bf0a44a8744469b5 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=620452 [2] https://src.fedoraproject.org/rpms/zsh/blob/f37/f/zsh.spec [3] Fedora toolbox commit 9bebde5bb60f36e3 https://src.fedoraproject.org/rpms/toolbox/c/9bebde5bb60f36e3 containers#1123 containers#840
The bash-completion and fish dependencies were already optional - the shell completions for Bash and fish won't be generated and installed if they are absent; and there's no dependency required for Z shell. So the install_completions build option wasn't reducing the dependency burden. The build option was a way to disable the generation and installation of the shell completions, regardless of whether the necessary dependencies are present or not. The only use-case for this is when installing to a non-system-wide prefix while hacking on Toolbox as a non-root user, because the locations for the completions advertised by the shells' APIs might not be accessible. Being able to disable the completions prevents the installation from failing. A different way of ensuring a smooth developer experience for a Toolbx hacker is to offer a way to change the locations where the shell completions are installed, which is necessary and beneficial for other use-cases. Z shell, unlike Bash's bash-completion.pc and fish's fish.pc, doesn't offer an API to detect the location for the shell completions. This means that Debian and Fedora use different locations [1, 2]. Namely, /usr/share/zsh/vendor-completions and /usr/share/zsh/site-functions. An option to specify the locations for the shell completions can optimize the build, if there's an alternate API for the location that doesn't involve using bash-completion.pc and fish.pc as build dependencies. eg., Fedora provides the _tmpfilesdir RPM macro to specify the location for vendor-supplied tmpfiles.d(5) files, which makes it possible to avoid having systemd.pc as a build dependency [3]. Fallout from bafbbe8 [1] Debian zsh commit bf0a44a8744469b5 https://salsa.debian.org/debian/zsh/-/commit/bf0a44a8744469b5 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=620452 [2] https://src.fedoraproject.org/rpms/zsh/blob/f37/f/zsh.spec [3] Fedora toolbox commit 9bebde5bb60f36e3 https://src.fedoraproject.org/rpms/toolbox/c/9bebde5bb60f36e3 containers#1123 containers#840
Initial work for fixing #836
I need to dig a bit more in the command completion generation to enhance the completions for args like distro.