[virt-tools-list] [virt-manager] [PATCH v2 00/10] Tab completion in bash shell via the argcomplete

Lin Ma lma at suse.com
Fri Dec 7 08:28:46 UTC 2018

v1 -> v2:
* Wrapper autocomplete function into cli.py to avoid to import argcomplete everywhere
* Move bash completion template file 'virtmanager' into data/bash-completion/ folder.
* Modify 'virtmanager', remove the complete lines. instead, The virt-* string will be
  added into virt-* scripts at build time.
* copy the 'virtmanager' to virt-* scripts in my_build instead of linking/deleting
  in my_install_data.
* Detect bash completion install location by function bash_completion_dir instead of
  hard code the location.
* Add a new patch about git ignore.

Hi all,

These draft patches add the tab completion in bash for virt-* utilities.

We've been using the argparse to help parse handling, So I think that the
argcomplete is a good option to deal with argument/sub-options completion
in bash shell for virt-manager project. Argcomplete returns the completion
result via fd 8.
After applying these patches, The python3 argcomplete is required while
running virt-* utilities.

For the details about argcomplete, Please refer to:
https://github.com/kislyuk/argcomplete  or

$ virt-clone --<TAB><TAB>
--auto-clone     --debug    --help     --nonsparse    --reflink
--check          --file     --mac      --nvram        --replace

$ virt-install --p<TAB><TAB>
--panic      --parallel   --paravirt   --pm         --print-xml  --pxe

$ virt-install --panic <TAB><TAB>
clearxml=  iobase=    model=

$ virt-install --panic model=isa,<TAB><TAB>
clearxml=  iobase=

$ virt-install --disk <TAB><TAB>
bus=    cache=      format=     path=   serial=     size=

$ virt-install --disk path=/storage/vms/sles15/disk0.raw,format=raw,<TAB><TAB>cache=none
bus=    format=     serial=     path=   size=

$ virt-install --network model=rtl8139,ty<TAB><TAB>
$ virt-install --network model=rtl8139,type=

* A side effect of patches is:
Due to the sub options of arguments of virt-* is comma separated, It needs
to add comma into $COMP_WORDBREAKS to support sub options completion.
That means, Once we used TAB for option completion, The change impacts the
current shell.

The completion support for virt-bootstrap will be posted to upstream after
these patches were accepted.

Lin Ma (10):
  Update docs to reflect the argcomplete dependency
  cli: Add the generic completer function and validator function
  virt-install: Add auto complete support for the general options
  virt-clone: Add auto complete support for the general options
  virt-xml: Add auto complete support for the general options
  virt-convert: Add auto complete support for the general options
  cli: Add auto complete support about sub options
  Bash completion template
  Don't track bash completion files due to they are generated
  setup.py: Install the bash completion files

 .gitignore                       |   1 +
 INSTALL.md                       |   1 +
 data/bash-completion/virtmanager |  37 +++++++++++
 setup.py                         |  27 ++++++++
 virt-clone                       |   2 +
 virt-convert                     |   2 +
 virt-install                     |   2 +
 virt-xml                         |   2 +
 virtinst/cli.py                  | 130 ++++++++++++++++++++++++++-------------
 9 files changed, 162 insertions(+), 42 deletions(-)
 create mode 100644 data/bash-completion/virtmanager


More information about the virt-tools-list mailing list