]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vsh: Add VSH_OT_NONE option type to catch programming errors
authorPeter Krempa <pkrempa@redhat.com>
Mon, 4 Mar 2024 14:40:40 +0000 (15:40 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 13 Mar 2024 14:02:51 +0000 (15:02 +0100)
Add a check that the default 0 assignment will not mean that an option
is considered to be VSH_OT_BOOL.

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

index 2cda6b575c1d6bd6996cae662ff5f7ed0ee1e00a..ad72b91d6c7048fbf527c748ee3c505a723965e7 100644 (file)
@@ -335,6 +335,11 @@ vshCmddefCheckInternals(vshControl *ctl,
             virBufferStrcat(&complbuf, opt->name, ", ", NULL);
 
         switch (opt->type) {
+        case VSH_OT_NONE:
+            vshError(ctl, "invalid type 'NONE' of option '%s' of command '%s'",
+                     opt->name, cmd->name);
+            return -1;
+
         case VSH_OT_BOOL:
             if (opt->completer || opt->completer_flags) {
                 vshError(ctl, "bool parameter '%s' of command '%s' has completer set",
@@ -671,6 +676,7 @@ vshCmddefHelp(const vshCmdDef *def)
                 }
                 break;
             case VSH_OT_ALIAS:
+            case VSH_OT_NONE:
                 /* aliases are intentionally undocumented */
                 continue;
             }
@@ -713,6 +719,7 @@ vshCmddefHelp(const vshCmdDef *def)
                            opt->name);
                 break;
             case VSH_OT_ALIAS:
+            case VSH_OT_NONE:
                 continue;
             }
 
index f4152c82946ee825e73ba172e8ca403551741049..c49bed9d59979ce594b366b41732c68527de3573 100644 (file)
@@ -85,6 +85,7 @@ typedef enum {
  * vshCmdOptType - command option type
  */
 typedef enum {
+    VSH_OT_NONE = 0, /* cannary to catch programming errors */
     VSH_OT_BOOL,     /* optional boolean option */
     VSH_OT_STRING,   /* optional string option */
     VSH_OT_INT,      /* optional or mandatory int option */