virsh: Remove hack using 'VSH_CMD_FLAG_ALIAS' to hide virsh commands

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>
This commit is contained in:
Peter Krempa 2021-09-16 15:57:28 +02:00
parent 4402bff1ec
commit 1726c572a2
4 changed files with 13 additions and 9 deletions

View 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,

View 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,

View 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")));

View 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, \
}