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

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



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

So while implementing this I realized it will not fly. At ARGV level it
is impossible to tell apart "--domain" and "--domain ". But the
difference is important, because in the first case we want to offer list
of all --options, while in the second case we want to call the --domain
completer. Okay, this might not be the best example because there's no
other option that shares the prefix, but for instance 'migrate' command
has:

    --timeout
    --timeout-suspend
    --timeout-postcopy

So if user types in:

  "virsh migrate --timeout"

we have to bring up list:

    "--timeout"
    "--timeout-suspend"
    "--timeout-postcopy"

and only after they type:

  "virsh migrate --timeout "

we can call --timeout completer. Since it's impossible to differentiate
these cases with VSH_OT_ARGV, I'm sticking with what I have now. Sure,
it might has its own problems but those can be solved later.

Michal


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