Re: [PATCH 00/11] Make auto completion better

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Attachment: signature.asc
Description: Digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux