]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vsh: Always assume that command groups are used
authorPeter Krempa <pkrempa@redhat.com>
Mon, 4 Mar 2024 14:51:28 +0000 (15:51 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 13 Mar 2024 13:53:01 +0000 (14:53 +0100)
None of the clients use the 'command set' approach and other pieces of
code such as the command validator already assume that command groups
are in use. Remove the unused 'command set' stuff.

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

index 95ff63baebc70b4eafcf7555a26200a0dfc7cf55..18cd279aba73cb28ecf091de2cca14e63a4ed144 100644 (file)
@@ -878,7 +878,7 @@ main(int argc, char **argv)
 
     virFileActivateDirOverrideForProg(argv[0]);
 
-    if (!vshInit(ctl, cmdGroups, NULL))
+    if (!vshInit(ctl, cmdGroups))
         exit(EXIT_FAILURE);
 
     if (!virshParseArgv(ctl, argc, argv) ||
index aaf6edb9a9c465acdb40f687ffbae3682efe2b95..f551b33c4b268f100701bce010e7b9538c4404bb 100644 (file)
@@ -1594,7 +1594,7 @@ main(int argc, char **argv)
 
     virFileActivateDirOverrideForProg(argv[0]);
 
-    if (!vshInit(ctl, cmdGroups, NULL))
+    if (!vshInit(ctl, cmdGroups))
         exit(EXIT_FAILURE);
 
     if (!vshAdmParseArgv(ctl, argc, argv) ||
index 4fe4d9166fa5872454d10f83371cd02fded905d1..a48cf0c76662e1571b6a0b8a1b66c4dec0cc571a 100644 (file)
@@ -56,7 +56,6 @@ vshControl *autoCompleteOpaque;
  * and only relies on static data accessible from the user-side callback
  */
 const vshCmdGrp *cmdGroups;
-const vshCmdDef *cmdSet;
 
 
 double
@@ -572,8 +571,8 @@ vshCommandCheckOpts(vshControl *ctl, const vshCmd *cmd, uint64_t opts_required,
     return -1;
 }
 
-static const vshCmdDef *
-vshCmdDefSearchGrp(const char *cmdname)
+const vshCmdDef *
+vshCmddefSearch(const char *cmdname)
 {
     const vshCmdGrp *g;
     const vshCmdDef *c;
@@ -588,28 +587,6 @@ vshCmdDefSearchGrp(const char *cmdname)
     return NULL;
 }
 
-static const vshCmdDef *
-vshCmdDefSearchSet(const char *cmdname)
-{
-    const vshCmdDef *s;
-
-    for (s = cmdSet; s->name; s++) {
-        if (STREQ(s->name, cmdname))
-            return s;
-        }
-
-    return NULL;
-}
-
-const vshCmdDef *
-vshCmddefSearch(const char *cmdname)
-{
-    if (cmdGroups)
-        return vshCmdDefSearchGrp(cmdname);
-    else
-        return vshCmdDefSearchSet(cmdname);
-}
-
 const vshCmdGrp *
 vshCmdGrpSearch(const char *grpname)
 {
@@ -1425,7 +1402,11 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser, vshCmd **partial)
                 if (cmd->flags & VSH_CMD_FLAG_ALIAS) {
                     VIR_FREE(tkdata);
                     tkdata = g_strdup(cmd->alias);
-                    cmd = vshCmddefSearch(tkdata);
+                    if (!(cmd = vshCmddefSearch(tkdata))) {
+                        /* self-test ensures that the alias exists */
+                        vshError(ctl, _("unknown command: '%1$s'"), tkdata);
+                        goto syntaxError;
+                    }
                 }
 
                 vshCmddefOptParse(cmd, &opts_need_arg, &opts_required);
@@ -1550,7 +1531,10 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser, vshCmd **partial)
                 if (STRNEQ(tmpopt->def->name, "help"))
                     continue;
 
-                help = vshCmddefSearch("help");
+                /* the self-test code ensures that help exists */
+                if (!(help = vshCmddefSearch("help")))
+                    break;
+
                 vshCommandOptFree(first);
                 first = g_new0(vshCmdOpt, 1);
                 first->def = help->opts;
@@ -3041,20 +3025,19 @@ vshInitDebug(vshControl *ctl)
  * Initialize global data
  */
 bool
-vshInit(vshControl *ctl, const vshCmdGrp *groups, const vshCmdDef *set)
+vshInit(vshControl *ctl, const vshCmdGrp *groups)
 {
     if (!ctl->hooks) {
         vshError(ctl, "%s", _("client hooks cannot be NULL"));
         return false;
     }
 
-    if (!groups && !set) {
-        vshError(ctl, "%s", _("command groups and command set cannot both be NULL"));
+    if (!groups) {
+        vshError(ctl, "%s", _("command groups must be non-NULL"));
         return false;
     }
 
     cmdGroups = groups;
-    cmdSet = set;
 
     if (vshInitDebug(ctl) < 0 ||
         (ctl->imode && vshReadlineInit(ctl) < 0))
@@ -3066,8 +3049,8 @@ vshInit(vshControl *ctl, const vshCmdGrp *groups, const vshCmdDef *set)
 bool
 vshInitReload(vshControl *ctl)
 {
-    if (!cmdGroups && !cmdSet) {
-        vshError(ctl, "%s", _("command groups and command are both NULL run vshInit before reloading"));
+    if (!cmdGroups) {
+        vshError(ctl, "%s", _("command groups is NULL run vshInit before reloading"));
         return false;
     }
 
@@ -3156,6 +3139,9 @@ cmdHelp(vshControl *ctl, const vshCmd *cmd)
     if ((def = vshCmddefSearch(name))) {
         if (def->flags & VSH_CMD_FLAG_ALIAS)
             def = vshCmddefSearch(def->alias);
+    }
+
+    if (def) {
         return vshCmddefHelp(def);
     } else if ((grp = vshCmdGrpSearch(name))) {
         return vshCmdGrpHelp(ctl, grp);
index 6f8e3895b7c87ac06fa5b7cc4255a6c3ee82d6b2..f4152c82946ee825e73ba172e8ca403551741049 100644 (file)
@@ -310,7 +310,7 @@ void vshPrint(vshControl *ctl, const char *format, ...)
     G_GNUC_PRINTF(2, 3);
 void vshPrintExtra(vshControl *ctl, const char *format, ...)
     G_GNUC_PRINTF(2, 3);
-bool vshInit(vshControl *ctl, const vshCmdGrp *groups, const vshCmdDef *set);
+bool vshInit(vshControl *ctl, const vshCmdGrp *groups);
 bool vshInitReload(vshControl *ctl);
 void vshDeinit(vshControl *ctl);
 void vshDebug(vshControl *ctl, int level, const char *format, ...)