]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Enforce proper ordering of options
authorMartin Kletzander <mkletzan@redhat.com>
Tue, 11 Nov 2014 10:01:05 +0000 (11:01 +0100)
committerMartin Kletzander <mkletzan@redhat.com>
Thu, 13 Nov 2014 14:44:23 +0000 (15:44 +0100)
Even though vshCmddefOptParse() tried returning -1 if there was an
optional option specification that preceded a required one, it failed to
check that for boolean type options and options with VSH_OFLAG_REQ_OPT
flag set.  On the other hand, it makes sense that VSH_OT_ARGV is
specified at the end of the option list.

Returning -1 enforces the proper ordering thanks to virsh-synopsis test
in 'make check'.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
tools/virsh.c

index 036b5173ab566fef793187b04b477f49777fcac9..41893bb071b921430c04975ddd2d3753cab9c309 100644 (file)
@@ -1073,6 +1073,7 @@ vshCmddefOptParse(const vshCmdDef *cmd, uint32_t *opts_need_arg,
         if (i > 31)
             return -1; /* too many options */
         if (opt->type == VSH_OT_BOOL) {
+            optional = true;
             if (opt->flags & VSH_OFLAG_REQ)
                 return -1; /* bool options can't be mandatory */
             continue;
@@ -1105,12 +1106,14 @@ vshCmddefOptParse(const vshCmdDef *cmd, uint32_t *opts_need_arg,
         if (opt->flags & VSH_OFLAG_REQ_OPT) {
             if (opt->flags & VSH_OFLAG_REQ)
                 *opts_required |= 1 << i;
+            else
+                optional = true;
             continue;
         }
 
         *opts_need_arg |= 1 << i;
         if (opt->flags & VSH_OFLAG_REQ) {
-            if (optional)
+            if (optional && opt->type != VSH_OT_ARGV)
                 return -1; /* mandatory options must be listed first */
             *opts_required |= 1 << i;
         } else {