From 7abb44f5f7313120b0d213155dc89d0a73bca74a Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 1 Mar 2024 23:14:51 +0100 Subject: [PATCH] vsh: Remove VSH_CMD_FLAG_ALIAS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's obvious that a command is an alias when the 'alias' property is set, thus an extra flag is redundant. Remove it. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- tools/virsh-nodedev.c | 1 - tools/virsh.c | 2 +- tools/virt-admin.c | 9 +-------- tools/vsh.c | 21 ++++++++------------- tools/vsh.h | 3 +-- 5 files changed, 11 insertions(+), 25 deletions(-) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index c08de65a96..b5a88b194f 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1415,7 +1415,6 @@ const vshCmdDef nodedevCmds[] = { .flags = 0 }, {.name = "nodedev-dettach", - .flags = VSH_CMD_FLAG_ALIAS, .alias = "nodedev-detach" }, {.name = "nodedev-dumpxml", diff --git a/tools/virsh.c b/tools/virsh.c index 18cd279aba..0d860d0390 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -460,7 +460,7 @@ virshUsage(void) fprintf(stdout, _(" %1$s (help keyword '%2$s')\n"), grp->name, grp->keyword); for (cmd = grp->commands; cmd->name; cmd++) { - if (cmd->flags & VSH_CMD_FLAG_ALIAS || + if (cmd->alias || cmd->flags & VSH_CMD_FLAG_HIDDEN) continue; fprintf(stdout, diff --git a/tools/virt-admin.c b/tools/virt-admin.c index f551b33c4b..27bd123bfe 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -1262,7 +1262,7 @@ vshAdmUsage(void) fprintf(stdout, _(" %1$s (help keyword '%2$s')\n"), grp->name, grp->keyword); for (cmd = grp->commands; cmd->name; cmd++) { - if (cmd->flags & VSH_CMD_FLAG_ALIAS || + if (cmd->alias || cmd->flags & VSH_CMD_FLAG_HIDDEN) continue; fprintf(stdout, @@ -1429,7 +1429,6 @@ static const vshCmdDef vshAdmCmds[] = { static const vshCmdDef monitoringCmds[] = { {.name = "srv-list", - .flags = VSH_CMD_FLAG_ALIAS, .alias = "server-list" }, {.name = "server-list", @@ -1439,7 +1438,6 @@ static const vshCmdDef monitoringCmds[] = { .flags = 0 }, {.name = "srv-threadpool-info", - .flags = VSH_CMD_FLAG_ALIAS, .alias = "server-threadpool-info" }, {.name = "server-threadpool-info", @@ -1449,7 +1447,6 @@ static const vshCmdDef monitoringCmds[] = { .flags = 0 }, {.name = "srv-clients-list", - .flags = VSH_CMD_FLAG_ALIAS, .alias = "client-list" }, {.name = "client-list", @@ -1465,7 +1462,6 @@ static const vshCmdDef monitoringCmds[] = { .flags = 0 }, {.name = "srv-clients-info", - .flags = VSH_CMD_FLAG_ALIAS, .alias = "server-clients-info" }, {.name = "server-clients-info", @@ -1479,7 +1475,6 @@ static const vshCmdDef monitoringCmds[] = { static const vshCmdDef managementCmds[] = { {.name = "srv-threadpool-set", - .flags = VSH_CMD_FLAG_ALIAS, .alias = "server-threadpool-set" }, {.name = "server-threadpool-set", @@ -1495,7 +1490,6 @@ static const vshCmdDef managementCmds[] = { .flags = 0 }, {.name = "srv-clients-set", - .flags = VSH_CMD_FLAG_ALIAS, .alias = "server-clients-set" }, {.name = "server-clients-set", @@ -1505,7 +1499,6 @@ static const vshCmdDef managementCmds[] = { .flags = 0 }, {.name = "srv-update-tls", - .flags = VSH_CMD_FLAG_ALIAS, .alias = "server-update-tls" }, {.name = "server-update-tls", diff --git a/tools/vsh.c b/tools/vsh.c index ad72b91d6c..63424fcf8f 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -268,21 +268,16 @@ vshCmddefCheckInternals(vshControl *ctl, g_auto(virBuffer) complbuf = VIR_BUFFER_INITIALIZER; /* in order to perform the validation resolve the alias first */ - if (cmd->flags & VSH_CMD_FLAG_ALIAS) { + if (cmd->alias) { const vshCmdDef *alias; - if (!cmd->alias) { - vshError(ctl, "command '%s' has inconsistent alias", cmd->name); - return -1; - } - if (!(alias = vshCmddefSearch(cmd->alias))) { vshError(ctl, "command alias '%s' is pointing to a non-existent command '%s'", cmd->name, cmd->alias); return -1; } - if (alias->flags & VSH_CMD_FLAG_ALIAS) { + if (alias->alias) { vshError(ctl, "command alias '%s' is pointing to another command alias '%s'", cmd->name, cmd->alias); return -1; @@ -303,7 +298,7 @@ vshCmddefCheckInternals(vshControl *ctl, return -1; } - if (cmd->flags & ~VSH_CMD_FLAG_ALIAS) { + if (cmd->flags != 0) { vshError(ctl, "command '%s' has multiple flags set", cmd->name); return -1; } @@ -615,7 +610,7 @@ vshCmdGrpHelp(vshControl *ctl, const vshCmdGrp *grp) grp->keyword); for (cmd = grp->commands; cmd->name; cmd++) { - if (cmd->flags & VSH_CMD_FLAG_ALIAS || + if (cmd->alias || cmd->flags & VSH_CMD_FLAG_HIDDEN) continue; vshPrint(ctl, " %-30s %s\n", cmd->name, @@ -1407,7 +1402,7 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser, vshCmd **partial) } /* aliases need to be resolved to the actual commands */ - if (cmd->flags & VSH_CMD_FLAG_ALIAS) { + if (cmd->alias) { VIR_FREE(tkdata); tkdata = g_strdup(cmd->alias); if (!(cmd = vshCmddefSearch(tkdata))) { @@ -2630,7 +2625,7 @@ 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].alias || cmds[cmd_list_index].flags & VSH_CMD_FLAG_HIDDEN) continue; @@ -3131,7 +3126,7 @@ cmdHelp(vshControl *ctl, const vshCmd *cmd) grp->keyword); for (def = grp->commands; def->name; def++) { - if (def->flags & VSH_CMD_FLAG_ALIAS || + if (def->alias || def->flags & VSH_CMD_FLAG_HIDDEN) continue; vshPrint(ctl, " %-30s %s\n", def->name, @@ -3145,7 +3140,7 @@ cmdHelp(vshControl *ctl, const vshCmd *cmd) } if ((def = vshCmddefSearch(name))) { - if (def->flags & VSH_CMD_FLAG_ALIAS) + if (def->alias) def = vshCmddefSearch(def->alias); } diff --git a/tools/vsh.h b/tools/vsh.h index c49bed9d59..57aa613382 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -162,8 +162,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 */ + VSH_CMD_FLAG_HIDDEN = (1 << 1), /* command is hidden/internal */ }; /*