Change the logic in a way, so that VSH_CMD_FLAG_ALIAS behaves similarly to
how VSH_OT_ALIAS for command options, i.e. there is no need for code duplication
for the alias and the aliased command structures. Along with that change,
switch any existing VSH_CMD_FLAG_ALIAS occurrences to this new format.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 tools/virsh-nodedev.c | 6 ++----
 tools/virsh.c         | 3 ++-
 tools/vsh.c           | 6 ++++++
 tools/vsh.h           | 1 +
 4 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index 321f15c..9446664 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -986,10 +986,8 @@ const vshCmdDef nodedevCmds[] = {
      .flags = 0
     },
     {.name = "nodedev-dettach",
-     .handler = cmdNodeDeviceDetach,
-     .opts = opts_node_device_detach,
-     .info = info_node_device_detach,
-     .flags = VSH_CMD_FLAG_ALIAS
+     .flags = VSH_CMD_FLAG_ALIAS,
+     .alias = "nodedev-detach"
     },
     {.name = "nodedev-dumpxml",
      .handler = cmdNodeDeviceDumpXML,
diff --git a/tools/virsh.c b/tools/virsh.c
index cb60edc..60fb02b 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -904,7 +904,8 @@ static const vshCmdDef virshCmds[] = {
      .handler = cmdSelfTest,
      .opts = NULL,
      .info = info_selftest,
-     .flags = VSH_CMD_FLAG_NOCONNECT | VSH_CMD_FLAG_ALIAS
+     .flags = VSH_CMD_FLAG_NOCONNECT | VSH_CMD_FLAG_ALIAS,
+     .alias = "self-test"
     },
     {.name = NULL}
 };
diff --git a/tools/vsh.c b/tools/vsh.c
index be6a073..ad3e1c7 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -1410,6 +1410,12 @@ vshCommandParse(vshControl *ctl, vshCommandParser 
*parser)
                     vshError(ctl, _("unknown command: '%s'"), tkdata);
                     goto syntaxError;   /* ... or ignore this command only? */
                 }
+                /* aliases need to be resolved to the actual commands */
+                if (cmd->flags & VSH_CMD_FLAG_ALIAS) {
+                    VIR_FREE(tkdata);
+                    tkdata = vshStrdup(ctl, cmd->alias);
+                    cmd = vshCmddefSearch(tkdata);
+                }
                 if (vshCmddefOptParse(cmd, &opts_need_arg,
                                       &opts_required) < 0) {
                     vshError(ctl,
diff --git a/tools/vsh.h b/tools/vsh.h
index e53910f..e383e54 100644
--- a/tools/vsh.h
+++ b/tools/vsh.h
@@ -179,6 +179,7 @@ struct _vshCmdDef {
     const vshCmdOptDef *opts;   /* definition of command options */
     const vshCmdInfo *info;     /* details about command */
     unsigned int flags;         /* bitwise OR of VSH_CMD_FLAG */
+    const char *alias;          /* name of the aliased command */
 };
 
 /*
-- 
2.5.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to