Re: [PATCH 08/11] tools: Provide bash autompletion file

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

 



On 11/08/2017 05:26 PM, Eric Blake wrote:
> On 11/08/2017 10:06 AM, Michal Privoznik wrote:
> 
>>> $ virsh complete some-command --arg partial<TAB><TAB>
>>
>> This is excatly what my patches are doing. With one tiny difference. In
>> fact bash script calls:
>>
>>   virsh complete "some-command --arg partial"
>>
>> so that I can have cmdComplete which takes exactly one string argument.
> 
> Ouch. That difference matters, and I don't think you want to do that.
> 
> We don't want to reimplement shell parsing; if the user does:
> 
> virsh snapshot-create-as 'domain with space' 'name with space'
> 'description with space', then my approach feeds those three arguments
> as is (the virsh parser doesn't have to undo any shell quoting), while
> your approach HAS to over-quote the original command line, then
> reimplement shell quoting to remove those quotes in virsh, in order to
> reconstruct the original line in spite of being temporarily squashed
> through one argument.

Right. On the other hand, who uses space in file names? ;-)

> 
>> Parsing of the string is then done within cmdComplete. I don't think
>> that we have variable args in virsh for commands, do we?
> 
> Yes, we do.  See 'virsh echo' for an example of its use.

Okay, I will look into this.

> 
>>
>> Correct. And again, my patches do this. For instance:
>>
>>   virsh -r -c qemu+ssh://host/system domifaddr --domain<TAB><TAB>
>>
>> becomes:
>>
>>   virsh -r -c qemu+ssh://host/system complete "domifaddr --domain"
>>
>> And it's the 'complete' command that is responsible for bringing up a
>> list of possible strings.
> 
> Ah, you are trying to put 'complete' after virsh-specific options (-r,
> -c), but before the command (domifaddr).

Yes.

> 
> And if properly implemented, you should be able to have:
> 
> virsh domif<TAB><TAB>
> 
> show 'domifaddr' (and any other commands starting with 'domif') (by
> calling "virsh complete -- domif"),

Yup. This works.

> 
> virsh domifaddr <TAB><TAB>
> 
> show both a list of domain names AND a list of --options accepted by
> domifaddr (by calling "virsh complete -- domifaddr ''"),

This is still WIP. As I mention in the cover letter, the parser is hard
to grasp for me and therefore this is yet to be implemented. Currently
all you get is list of --options. However, completers for --option work.
For instance:

virsh start --domain <TAB><TAB>

brings up list of domains to start.

> 
> virsh domifaddr --<TAB><TAB>
> 
> show a list of long options for domifaddr (by calling "virsh complete --
> domifaddr --") (yes, I'm specifically making sure the second '--'
> doesn't get eaten by getopts, by inserting 'complete --' rather than
> just 'complete'), and
> 
> virsh domifaddr a<TAB><TAB>
> 
> show a filtered list of just domain names starting with 'a' (by calling
> "virsh complete domifaddr a").
> 
> That is, the completions should be context-sensitive based on how much
> of the command line is present prior to the <TAB><TAB>, and should NOT
> need the user to type an explicit --domain just to get domain completions.
> 

Yeah, that's the idea. And I'm looking into the code, but it's not that
easy for me to understand it. So, if anybody wants to help, be my guest.

Michal

--
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