[libvirt] [PATCH RFC 0/2] virsh: Introduce basic autocompletion

Michal Privoznik mprivozn at redhat.com
Tue Oct 31 13:10:25 UTC 2017

This is supposed to go on the top of:


Before digging any deeper to this hole I want to make sure that
this approach is acceptable.

So how does this work. The idea is to have handful of generic
functions that fetch names (so called completers). Basically, one
completer per each libvirt object. The returned names are then
matched against (partial) user input and only matching strings
are then offered to the user. Moreover, among having .completer
each option has .completer_flags which can refine the completer's

For instance, in 2/2 I'm introducing virshDomainNameCompleter()
which does nothing more than virConnectListAllDomains(). However,
since it doesn't make much sense to start already running domain,
for the 'start' command .completer_flags is set to
VIR_CONNECT_LIST_DOMAINS_INACTIVE so that only inactive domains
are returned in the list.

What is missing?
What is implemented here are vshCmdOptDef completers. The general
vshCmdDef completers are still missing. Therefore:

virsh # start --domain<TAB><TAB>

works and lists inactive domains, but:

virsh # start<TAB><TAB>

doesn't (well, apart from offering options for the 'start'
command). While that would be certainly nice feature to have,
it'd require more work, because some arguments are "implicit"
based on position. For instance:

virsh # attach-interface fedora network default

which is equivalent to:

virsh # attach-interface --domain fedora --type network --source default

Also, bash autocompletion is missing. The idea there is to have
an unlisted virsh command that the bash script can call in order
to fetch list of options. But again, no movement in that area

Michal Privoznik (2):
  vsh: Call vshCmdOptDef.completer properly
  virsh: Introduce virshDomainNameCompleter

 tools/virsh-domain-monitor.c |  30 +++----
 tools/virsh-domain.c         | 182 ++++++++++++++++++++++---------------------
 tools/virsh-snapshot.c       |  24 +++---
 tools/virsh.c                |  43 ++++++++++
 tools/virsh.h                |   8 +-
 tools/vsh.c                  |  45 ++++++-----
 6 files changed, 194 insertions(+), 138 deletions(-)


More information about the libvir-list mailing list