[libvirt] [PATCH 00/11] Make auto completion better

Martin Kletzander mkletzan at redhat.com
Wed Nov 8 15:41:23 UTC 2017


On Tue, Nov 07, 2017 at 01:22:48PM +0100, Michal Privoznik wrote:
>After initial RFC [1] I had some time to work on this and here is
>the result.
>
>
>What's implemented?
>===================
>Auto completion for both interactive and non-interactive
>virsh/virt-admin.
>
>
>Known limitations
>=================
>Currently, just options completers work. I mean, to bring up list
>of domains you have to:
>
>  virsh # start --domain <TAB><TAB>
>
>Doing bare:
>
>  virsh # start <TAB><TAB>
>
>brings up list of --options. I am working on this meanwhile. But
>one can argue that having to use --option is not that much of a
>problem since we have good completion now.
>
>The other known limitation - and actually room for others to join
>and help - is missing completers. I mean, the last 3 patches give
>an example how to do that. But that is still very few. We need
>more completers.
>
>
>How does this work?
>===================
>The basic idea is simple, when defining opts for command two new
>struct members can be set:
>
>     {.name = "mac",
>      .type = VSH_OT_STRING,
>+     .completer = virshDomainInterfaceCompleter,
>+     .completer_flags = VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC,
>      .help = N_("MAC address")
>     },
>
>@completer is the callback that is used when user wants to bring
>up list of possible strings. @completer_flags can then be used to
>refine return value of @completer. In this specific example,
>virshDomainInterfaceCompleter() brings up list of interfaces for
>given domain. It tries to return /interface/target/@dev but if
>not found (e.g. because domain is not running),
>/interface/mac/@address is returned otherwise. However, in one
>specific case we are interested only in MAC addresses (regardless
>of domain state) and thus VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC
>flag is specified which alters @completer behaviour.
>
>For non-interactive virsh/virt-admin there's
>tools/bash-completion/vsh script which does no more than calling:
>
>  $1 complete $USER_INPUT
>
>(where $1 is name of the binary user intents to run).
>
>
>How to test this?
>=================
>
>Interactive completion should work out of the box. Just make sure
>you're connected. Completers don't connect! You certainly don't
>want ssh's 'Password:' prompt show on <TAB><TAB>, do you?
>Non-interactive completers do connect, but in order to avoid any
>password prompts, /dev/stdin is closed before anything else is
>done. In order to test it, just:
>
>  libvirt.git $ source tools/bash-completion/vsh
>
>Now, bash completion should work:
>
>  libvirt.git $ ./tools/virsh -c qemu:///system start --domain <TAB><TAB>
>

So if I do this, it works, but if I copy it where it is supposed to be installed
it doesn't for some reason.  I haven't dug into that, I don't even know where to
start, probably.  Also it is very possible that it's my fault.

I also found one more thing, but that's only easy to fix in few cases.  If you
type 'virsh start --domain fedora <TAB><TAB>' then one of the strings it offers
is '--domain'.  It'd be nice to have that filtered out.  Not needed for ACK,
though.  Just an idea for you.

Apart from that it looks sane, so ACK to the general concept, I would just
change 2/11 as written in the reply, drop (or completely replace) 3/11 and
instead do the '-qq' thing.  And of course adjust other code depending on that.
I'd ACK the rest, I would just like to have the middle-of-the-command completion
working too so it doesn't confuse people.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20171108/873d1484/attachment-0001.sig>


More information about the libvir-list mailing list