]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Remove hack using 'VSH_CMD_FLAG_ALIAS' to hide virsh commands
authorPeter Krempa <pkrempa@redhat.com>
Thu, 16 Sep 2021 13:57:28 +0000 (15:57 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 17 Sep 2021 07:40:46 +0000 (09:40 +0200)
Introduce a proper flag 'VSH_CMD_FLAG_HIDDEN' for hiding commands from
output so that we can validate that there aren't any loops or
misconfigured commands.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tools/virsh.c
tools/virt-admin.c
tools/vsh.c
tools/vsh.h

index ce5fd247dd2ec9cde7f5a2102d3db097c08b35ae..3c6f60f17629ca359903a0f0cdb0faa1d3f04968 100644 (file)
@@ -464,7 +464,8 @@ virshUsage(void)
         fprintf(stdout, _(" %s (help keyword '%s')\n"),
                 grp->name, grp->keyword);
         for (cmd = grp->commands; cmd->name; cmd++) {
-            if (cmd->flags & VSH_CMD_FLAG_ALIAS)
+            if (cmd->flags & VSH_CMD_FLAG_ALIAS ||
+                cmd->flags & VSH_CMD_FLAG_HIDDEN)
                 continue;
             fprintf(stdout,
                     "    %-30s %s\n", cmd->name,
index c8e7ee794ae8fefda2ea50e979409ee54639f393..c0818e850a1050beba7f9d509bd39c5c88bd7eaa 100644 (file)
@@ -1235,7 +1235,8 @@ vshAdmUsage(void)
         fprintf(stdout, _(" %s (help keyword '%s')\n"),
                 grp->name, grp->keyword);
         for (cmd = grp->commands; cmd->name; cmd++) {
-            if (cmd->flags & VSH_CMD_FLAG_ALIAS)
+            if (cmd->flags & VSH_CMD_FLAG_ALIAS ||
+                cmd->flags & VSH_CMD_FLAG_HIDDEN)
                 continue;
             fprintf(stdout,
                     "    %-30s %s\n", cmd->name,
index ea078c707bc5ccd7131b27dfd7a564a511ddf8ab..eb17a58dc0ccdf8b6d562b4cdfe2d01ea123ade9 100644 (file)
@@ -577,7 +577,8 @@ vshCmdGrpHelp(vshControl *ctl, const vshCmdGrp *grp)
              grp->keyword);
 
     for (cmd = grp->commands; cmd->name; cmd++) {
-        if (cmd->flags & VSH_CMD_FLAG_ALIAS)
+        if (cmd->flags & VSH_CMD_FLAG_ALIAS ||
+            cmd->flags & VSH_CMD_FLAG_HIDDEN)
             continue;
         vshPrint(ctl, "    %-30s %s\n", cmd->name,
                  _(vshCmddefGetInfo(cmd, "help")));
@@ -2544,7 +2545,8 @@ vshReadlineCommandGenerator(void)
         for (cmd_list_index = 0; cmds[cmd_list_index].name; cmd_list_index++) {
             const char *name = cmds[cmd_list_index].name;
 
-            if (cmds[cmd_list_index].flags & VSH_CMD_FLAG_ALIAS)
+            if (cmds[cmd_list_index].flags & VSH_CMD_FLAG_ALIAS ||
+                cmds[cmd_list_index].flags & VSH_CMD_FLAG_HIDDEN)
                 continue;
 
             VIR_REALLOC_N(ret, ret_size + 2);
@@ -3029,7 +3031,8 @@ cmdHelp(vshControl *ctl, const vshCmd *cmd)
                      grp->keyword);
 
             for (def = grp->commands; def->name; def++) {
-                if (def->flags & VSH_CMD_FLAG_ALIAS)
+                if (def->flags & VSH_CMD_FLAG_ALIAS ||
+                    def->flags & VSH_CMD_FLAG_HIDDEN)
                     continue;
                 vshPrint(ctl, "    %-30s %s\n", def->name,
                          _(vshCmddefGetInfo(def, "help")));
index 39f70913fe7b2965381bb0e606da62a4720a340e..ae50f6b220a11c22d909764844573e1a4088dff1 100644 (file)
@@ -163,6 +163,7 @@ struct _vshCmdOpt {
 enum {
     VSH_CMD_FLAG_NOCONNECT = (1 << 0),  /* no prior connection needed */
     VSH_CMD_FLAG_ALIAS     = (1 << 1),  /* command is an alias */
+    VSH_CMD_FLAG_HIDDEN    = (1 << 2),  /* command is hidden/internal */
 };
 
 /*
@@ -446,8 +447,7 @@ bool cmdComplete(vshControl *ctl, const vshCmd *cmd);
         .handler = cmdSelfTest, \
         .opts = NULL, \
         .info = info_selftest, \
-        .flags = VSH_CMD_FLAG_NOCONNECT | VSH_CMD_FLAG_ALIAS, \
-        .alias = "self-test" \
+        .flags = VSH_CMD_FLAG_NOCONNECT | VSH_CMD_FLAG_HIDDEN, \
     }
 
 #define VSH_CMD_COMPLETE \
@@ -456,8 +456,7 @@ bool cmdComplete(vshControl *ctl, const vshCmd *cmd);
         .handler = cmdComplete, \
         .opts = opts_complete, \
         .info = info_complete, \
-        .flags = VSH_CMD_FLAG_NOCONNECT | VSH_CMD_FLAG_ALIAS, \
-        .alias = "complete" \
+        .flags = VSH_CMD_FLAG_NOCONNECT | VSH_CMD_FLAG_HIDDEN, \
     }