[virt-tools-list] [virt-manager] [RFC PATCH 0/9] Tab completion in bash shell via the argcomplete

Lin Ma lma at suse.com
Wed Nov 14 08:26:37 UTC 2018


On 11/14/18 4:12 PM, Lin Ma wrote:
> 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
> https://pypi.org/project/argcomplete/
>
> ex:
> $ 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=
> ...

The already specified sub options which before <TAB> won't be provided.
So the above completion result should be:
...
bus=     cache=      serial=      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 (9):
>    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 file
>    setup.py: Install and link the bash completion scripts
>
>   INSTALL.md                  |   1 +
>   bash-completion/virtmanager |  40 ++++++++++++
>   setup.py                    |  10 +++
>   virt-clone                  |   3 +
>   virt-convert                |   4 ++
>   virt-install                |   3 +
>   virt-xml                    |   4 ++
>   virtinst/cli.py             | 121 +++++++++++++++++++++++-------------
>   8 files changed, 144 insertions(+), 42 deletions(-)
>   create mode 100644 bash-completion/virtmanager
>




More information about the virt-tools-list mailing list