]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vsh: Introduce annotation for vsh options which are unexpectedly parsed positionally
authorPeter Krempa <pkrempa@redhat.com>
Wed, 13 Mar 2024 21:31:20 +0000 (22:31 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 2 Apr 2024 12:24:29 +0000 (14:24 +0200)
Based on the rationale in previous commit, all commands which were
parsed as positional but not documented as such will be annotated with
this flag.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/vsh.c
tools/vsh.h

index 96d6a5c238b55bdc7a8abdbae08a76619cb5720c..eeee58d39e0dfd4933d47caa072bf201660e2b08 100644 (file)
@@ -334,7 +334,8 @@ vshCmddefCheckInternals(vshControl *ctl,
             case VSH_OT_ARGV:
                 if (brokenPositionals == 0 ||
                     brokenPositionals == opt->type) {
-                    if (!(opt->flags & VSH_OFLAG_REQ_OPT) && !opt->positional)
+                    if (!(opt->flags & VSH_OFLAG_REQ_OPT) &&
+                        !(opt->positional || opt->unwanted_positional))
                         virBufferStrcat(&posbuf, opt->name, ", ", NULL);
                 }
                 break;
@@ -363,6 +364,12 @@ vshCmddefCheckInternals(vshControl *ctl,
             return -1;
         }
 
+        if (opt->unwanted_positional && opt->positional) {
+            vshError(ctl, "unwanted_positional flag of argument '%s' of command '%s' must not be used together with positional",
+                     opt->name, cmd->name);
+            return -1;
+        }
+
         switch (opt->type) {
         case VSH_OT_NONE:
             vshError(ctl, "invalid type 'NONE' of option '%s' of command '%s'",
@@ -376,7 +383,7 @@ vshCmddefCheckInternals(vshControl *ctl,
                 return -1;
             }
 
-            if (opt->positional) {
+            if (opt->positional || opt->unwanted_positional) {
                 vshError(ctl, "boolean parameter '%s' of command '%s' must not be positional",
                          opt->name, cmd->name);
                 return -1;
@@ -397,6 +404,7 @@ vshCmddefCheckInternals(vshControl *ctl,
 
             if (opt->required ||
                 opt->positional ||
+                opt->unwanted_positional ||
                 opt->completer ||
                 opt->flags ||
                 !opt->help) {
index cd833a55fa71da4f5698d92e86668dce11191b62..fdcc89b12a276910c2b3bb72b37427e1efb7920b 100644 (file)
@@ -133,6 +133,13 @@ struct _vshCmdOptDef {
     vshCmdOptType type;         /* option type */
     bool required;              /* option is required */
     bool positional;            /* option is a positional option (not requiring '--optionname') */
+
+    /* Historically the command parser in virsh allowed many optional arguments
+     * which were documented as non-positional to be filled positionally. To
+     * preserve this functionality those need to be annotated with the
+     * 'unwanted_positional' flag. New options must not use this flag */
+    bool unwanted_positional;
+
     unsigned int flags;         /* flags */
     const char *help;           /* non-NULL help string; or for VSH_OT_ALIAS
                                  * the name of a later public option */