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

Click's completion system has been rewritten #37

Open
davidism opened this issue Oct 3, 2020 · 1 comment
Open

Click's completion system has been rewritten #37

davidism opened this issue Oct 3, 2020 · 1 comment

Comments

@davidism
Copy link
Member

davidism commented Oct 3, 2020

See pallets/click#1484 and pallets/click#1622. The documentation can be found here for now: https://click.palletsprojects.com/en/8.0.x/shell-completion/. In the new system:

  • Each shell can provide completion is a completely different way if needed.
  • It's possible to register support for other shells.
  • Every core object (command, group, chained group, argument, option, type) provides a shell_complete method that provides completions at that level and can be overridden. Parameters additionally accept a shell_complete function in __init__ to override or extend the type's completion.
  • Values for choice, file, path, and directories are completed. Path support is handled by the shell rather than emulated in Click.
  • Arbitrary metadata can be attached to completions, which shell support could use however it likes in the completion script.

However, Click doesn't provide these features:

  • Built-in PowerShell support. This could be added to Click, but my preference right now is for an extension to provide other shell support.
  • An install command. This is probably out of scope for Click.
  • Shell detection. This is out of scope for Click since it relies on an external dependency. I didn't consider implementing it because the method for loading the completion differs between shells anyway, so it's not any extra work to add the shell to the instruction.

Due to all these changes, the click-completion won't work with the next release of Click. We've talked about merging this project into Click before, but I think we pretty much have what we want in core at this point. One option is to make a release that specifies click<8 in install_requires, then have the next version specify click>=8 and continue to support the parts that Click doesn't provide.

@ssbarnea
Copy link
Contributor

I am bit disappointed that click refuses to provide a full end-to-end solution for enabling completion on shell tools.

I would really wish someone finds a way to auto-install these extensions when the the tool runs first time, or at least to prompt user to do that. Also installation should be done in a way that degrades gracefully, for example if user removes the tool, we do not want to see an error next time he logs in.

If anyone has an example that makes the installation much easier for the users, so tool authors do not need to write extensive documentation for each shell, it would really be useful. Personally I am interested to cover only bash and zsh for start.

tilsche added a commit to metricq/metricq-python that referenced this issue Jun 1, 2023
Shell completion is now supported by click itself and the extra package is dead.

click-contrib/click-completion#37
click-contrib/click-completion#41

It is still not trivial to use because it needs to be enabled for the shell.
And maybe is and always was impossible for these example .py files because they are not real commands anyway.

https://click.palletsprojects.com/en/8.1.x/shell-completion/
tilsche added a commit to metricq/metricq-python that referenced this issue Jun 1, 2023
Shell completion is now supported by click itself and the extra package is dead.

click-contrib/click-completion#37
click-contrib/click-completion#41

It is still not trivial to use because it needs to be enabled for the shell.
And maybe is and always was impossible for these example .py files because they are not real commands anyway.

https://click.palletsprojects.com/en/8.1.x/shell-completion/
tilsche added a commit to metricq/metricq-source-sysinfo that referenced this issue Jun 1, 2023
Shell completion is now supported by click itself and the extra package is dead.

click-contrib/click-completion#37
click-contrib/click-completion#41

It is still not trivial to use because it needs to be enabled for the shell.
And maybe is and always was impossible for these example .py files because they are not real commands anyway.

https://click.palletsprojects.com/en/8.1.x/shell-completion/
tilsche added a commit to metricq/metricq-python that referenced this issue Jun 1, 2023
Shell completion is now supported by click itself and the extra package is dead.

click-contrib/click-completion#37
click-contrib/click-completion#41

It is still not trivial to use because it needs to be enabled for the shell.
And maybe is and always was impossible for these example .py files because they are not real commands anyway.

https://click.palletsprojects.com/en/8.1.x/shell-completion/
tilsche added a commit to metricq/metricq-tools that referenced this issue Jun 2, 2023
Shell completion is now supported by click itself and the extra package is dead.

click-contrib/click-completion#37
click-contrib/click-completion#41

It is still not trivial to use because it needs to be enabled for the shell.
And maybe is and always was impossible for these example .py files because they are not real commands anyway.

https://click.palletsprojects.com/en/8.1.x/shell-completion/
@untitaker untitaker pinned this issue Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants