]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vshCmddefCheckInternals: Improve some checks
authorPeter Krempa <pkrempa@redhat.com>
Thu, 14 Mar 2024 09:31:17 +0000 (10:31 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 2 Apr 2024 12:24:29 +0000 (14:24 +0200)
 - move the check that completer_flags are 0 if no completer is set
   into a common place and remove duplication
 - add check that _BOOL arguments are not positional
 - add missing checks to _ALIAS

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

index e6ea3a398aeff090dd8f9b3373319e3205531e90..a4235905dc16b42aaa76fdc364cb85aac5366776 100644 (file)
@@ -332,6 +332,13 @@ vshCmddefCheckInternals(vshControl *ctl,
             return -1;
         }
 
+        /* Mandate no completer flags if no completer is specified */
+        if (opt->completer_flags != 0 && !opt->completer) {
+            vshError(ctl, "completer_flags of argument '%s' of command '%s' must be 0 if no completer is used",
+                     opt->name, cmd->name);
+            return -1;
+        }
+
         switch (opt->type) {
         case VSH_OT_NONE:
             vshError(ctl, "invalid type 'NONE' of option '%s' of command '%s'",
@@ -339,12 +346,18 @@ vshCmddefCheckInternals(vshControl *ctl,
             return -1;
 
         case VSH_OT_BOOL:
-            if (opt->completer || opt->completer_flags) {
+            if (opt->completer) {
                 vshError(ctl, "bool parameter '%s' of command '%s' has completer set",
                          opt->name, cmd->name);
                 return -1;
             }
 
+            if (opt->positional) {
+                vshError(ctl, "boolean parameter '%s' of command '%s' must not be positional",
+                         opt->name, cmd->name);
+                return -1;
+            }
+
             if (opt->required) {
                 vshError(ctl, "parameter '%s' of command '%s' misused 'required' flag",
                          opt->name, cmd->name);
@@ -358,7 +371,11 @@ vshCmddefCheckInternals(vshControl *ctl,
             g_autofree char *name = NULL;
             char *p;
 
-            if (opt->flags || !opt->help) {
+            if (opt->required ||
+                opt->positional ||
+                opt->completer ||
+                opt->flags ||
+                !opt->help) {
                 vshError(ctl, "parameter '%s' of command '%s' has incorrect alias option",
                          opt->name, cmd->name);
                 return -1;