volttron
volttron copied to clipboard
new-feature/cli-auto-complete
Is your feature request related to a problem? Please describe. Allow CLI command auto-complete, e.g., vctl
Describe the solution you'd like Using argcomplete package: https://kislyuk.github.io/argcomplete/
Additional context
A demo codebase is available at: new-feature/cli-auto-complete
Steps to reproduce
- run
python3 bootstrap.py
- run
source env/bin/activate
- run
pip install argcomplete
- run
chmod +x enable-auto-complete.sh
- run
bash enable-auto-complete.sh
Note: as suggested in https://kislyuk.github.io/argcomplete/#global-completion If you choose not to use global completion, or ship a bash completion module that depends on argcomplete, you must register your script explicitly using eval "$(register-python-argcomplete my-awesome-script)".
https://user-images.githubusercontent.com/28743873/209247351-e1a78345-c078-4f1b-97cd-5fceb68b00a9.mp4
~~### Intermediate solution (tested on Ubuntu 20.04)~~
(Update at 1229. This is not a stable solution)
As suggested by https://github.com/kislyuk/argcomplete#readme. In this way, as long as the runnable is accessible, we don’t have to run “eval "$(register-python-argcomplete
Install a global argcomplete
One issue when running “activate-global-python-argcomplete” is "permission denied". And a walk-around is to first use --user
then manually cp
to the “/etc/bash_completion.d/” folder
$ activate-global-python-argcomplete
Installing bash completion script /etc/bash_completion.d/python-argcomplete
usage: activate-global-python-argcomplete [-h] [--dest DEST] [--user] [--no-defaults] [--complete-arguments ...]
activate-global-python-argcomplete: error: [Errno 13] Permission denied: '/etc/bash_completion.d/python-argcomplete'
Please try --user to install into a user directory, or --dest to specify the bash completion modules directory
$ activate-global-python-argcomplete --user
Installing bash completion script /home/kefei/.bash_completion.d/python-argcomplete
$ sudo cp /home/kefei/.bash_completion.d/python-argcomplete /etc/bash_completion.d/python-argcomplete
[sudo] password for kefei:
Also note that, there is no need to add “PYTHON_ARGCOMPLETE_OK” for argcomplete v2.0.0. but the "EASY-INSTALL-ENTRY-SCRIPT” handle that. Here is an working example for vctl is at control_parser.py
especially