Add completions for CLI - #1118
lewisacidic wants to merge 1 commit into
Conversation
Uses `argcomplete` to add basic completions to the cli.
|
sorry, don't really want to add a dependency for this |
|
also the strategy used by argcomplete is too slow to be useful, it adds ~200ms per I believe the more correct way to do something like this would be to pregenerate completions as part of the packaging and provide those separately |
|
Thanks for the quick reply. In my opinion completions are pretty important for friendly, usable CLI tools. I understand pre-commit isn't first and foremost a CLI tool, but I found I missed completions when I was trying to remember how to install a commit-msg hook just now (typing I guess we could write completions by hand for the relatively small number of available commands and not need any new dependencies, but this is definitely the easiest and most integrated way to provide completions. |
|
it's not particularly difficult to generate completions scripts, here's some prior art: https://github.com/asottile/all-repos/blob/master/all_repos/complete.py Would expose some command like: eval "$(pre-commit complete)"which you could put in your rc file |
|
Just seen your followups, yep it's laggy (tbh I'm using WSL so I'm used to laggy terminals, didn't really notice...). I think the lag could be alleviated with a refactor to avoid importing before parsing CLIs, I've used this style of autocompletion before and it worked a charm. In any case, I don't really have the time to invest into writing anything substantial right now, shall I close this and open an issue about completions instead? |
|
yeah I don't really want to play the import whackamole game -- there's not a good reason to runtime-compute completions when we can generate them all statically |
Uses
argcompleteto trivially add basic completions to the cli.This allows things like:
And
Which can be tab toggled through once the correct completions are registered (at least in
fish, I didn't try other shells yet).This is pretty basic (as might be expected from adding 2 simple lines of code!!!), it would be really nice to do a bit more, such as getting a list of the available hooks and completing
pre-commit run <TAB>with them.Also, at least with
clickCLIs, you should be able to get help messages showing up (infishat least) which is nicer than this. Of course, this would require a rewrite of the parser code to use click...Any opinions about this sort of functionality?