]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vsh: Extend checks for aliased commands
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 17 Sep 2021 07:52:43 +0000 (09:52 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 21 Sep 2021 08:20:41 +0000 (10:20 +0200)
If a command is an alias, then it can only have .name, .flags and
.alias set and .flags should contain just VSH_CMD_FLAG_ALIAS.
Check if that's the case in self-test.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/vsh.c

index 9057310077c8b2315cd682b841f0db1625dccbe7..dd6930730d097fa3d82cf0c30a48737314f89f51 100644 (file)
@@ -290,6 +290,26 @@ vshCmddefCheckInternals(vshControl *ctl,
             return -1;
         }
 
+        if (cmd->handler) {
+            vshError(ctl, _("command '%s' has handler set"), cmd->name);
+            return -1;
+        }
+
+        if (cmd->opts) {
+            vshError(ctl, _("command '%s' has options set"), cmd->name);
+            return -1;
+        }
+
+        if (cmd->info) {
+            vshError(ctl, _("command '%s' has info set"), cmd->name);
+            return -1;
+        }
+
+        if (cmd->flags & ~VSH_CMD_FLAG_ALIAS) {
+            vshError(ctl, _("command '%s' has multiple flags set"), cmd->name);
+            return -1;
+        }
+
         /* we don't need to continue as the real command will be checked separately */
         return 0;
     }