]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
add VSH_OFLAG_REQ_OPT options
authorLai Jiangshan <laijs@cn.fujitsu.com>
Tue, 7 Jun 2011 09:11:10 +0000 (17:11 +0800)
committerEric Blake <eblake@redhat.com>
Tue, 14 Jun 2011 17:40:52 +0000 (11:40 -0600)
A VSH_OFLAG_REQ_OPT option means --optionname is required when used.
It will kill any ambiguity, even a !VSH_OFLAG_REQ option listed before
a VSH_OFLAG_REQ option, if the !VSH_OFLAG_REQ option is a
VSH_OFLAG_REQ_OPT option.

It will help us use optional argument with VSH_OT_ARGV argument.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
tools/virsh.c

index d2f4020ee2a75a89a477de75af1a9928f36ab93e..5ce3d2209490121edd4dfb4fa5c3b00a64548f4c 100644 (file)
@@ -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 */
@@ -11453,6 +11454,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;
+        }
+
         *opts_need_arg |= 1 << i;
         if (opt->flag & VSH_OFLAG_REQ) {
             if (optional)