[libvirt] [PATCH 03/10 V2] add VSH_OFLAG_REQ_OPT options

Eric Blake eblake at redhat.com
Tue Jun 14 17:53:51 UTC 2011


On 06/13/2011 04:47 PM, Daniel P. Berrange wrote:
> On Tue, Jun 07, 2011 at 05:11:10PM +0800, Lai Jiangshan wrote:
>> A VSH_OFLAG_REQ_OPT option means --optionname is required when used.
>> It will kill any ambiguity even !VSH_OFLAG_REQ option listed before
>> VSH_OFLAG_REQ option if the !VSH_OFLAG_REQ option is a VSH_OFLAG_REQ_OPT option.
>>
>> It will help us use optional arguement with VSH_OT_ARGV argument.

s/arguement/argument/

>>
>> Signed-off-by: Lai Jiangshan <laijs at cn.fujitsu.com>
>> ---
>>  tools/virsh.c |    7 +++++++
>>  1 files changed, 7 insertions(+), 0 deletions(-)
>>
>> diff --git a/tools/virsh.c b/tools/virsh.c
>> index 638029c..d13c12b 100644
>> --- a/tools/virsh.c
>> +++ b/tools/virsh.c
>> @@ -152,6 +152,7 @@ enum {
>>      VSH_OFLAG_NONE     = 0,        /* without flags */
>>      VSH_OFLAG_REQ      = (1 << 0), /* option required */
>>      VSH_OFLAG_EMPTY_OK = (1 << 1), /* empty string option allowed */
>> +    VSH_OFLAG_REQ_OPT  = (1 << 2), /* --optionname required */
>>  };
>>  
>>  /* dummy */
>> @@ -11375,6 +11376,12 @@ vshCmddefOptParse(const vshCmdDef *cmd, uint32_t* opts_need_arg,
>>                  return -1; /* bool options can't be mandatory */
>>              continue;
>>          }
>> +        if (opt->flag & VSH_OFLAG_REQ_OPT) {
>> +            if (opt->flag & VSH_OFLAG_REQ)
>> +                *opts_required |= 1 << i;
>> +            continue;
>> +        }
>> +

I had to look ahead to patch 9/10 to see where this was used, but it
makes sense now:

virsh send-key domain linux 37 18 21

would be problematic (since the parser would try to associate linux as
the first var-arg, but var-arg wants only keycodes), while:

virsh send-key domain --codeset linux 37 18 21

makes it obvious that the --codeset was required for proper parsing.
All because send-key, unlike echo, must have at least one keycode arg.

If I'm not mistaken, this also means:

virsh send-key domain 37 18 21 --codeset linux

works (which is fine by me), whereas:

virsh send-key domain -- 37 18 21 --codeset linux

tries to parse "--codeset" and "linux" as keycodes.

>>          *opts_need_arg |= 1 << i;
>>          if (opt->flag & VSH_OFLAG_REQ) {
>>              if (optional)
> 
> ACK

Pushed (note that 2/10 is still unpushed, while waiting for an ACK on my
v2 variant to address review comments on v1).

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110614/3fa8e31a/attachment-0001.sig>


More information about the libvir-list mailing list