]> git.cworth.org Git - apitrace/commitdiff
cli: Add an alias mechanism and alias "retrace" to "replay"
authorCarl Worth <cworth@cworth.org>
Mon, 11 Feb 2013 22:56:15 +0000 (14:56 -0800)
committerJosé Fonseca <jfonseca@vmware.com>
Fri, 22 Feb 2013 16:34:20 +0000 (16:34 +0000)
This allows any existing scripts calling "apitrace retrace" to
continue to work.

cli/cli_main.cpp

index 040adcf82928c56f8a35b76617ddeb72b11e1689..d6db6196121b3d5a9a158c29309c1e7f556a02c8 100644 (file)
@@ -79,6 +79,18 @@ static const Command * commands[] = {
     &help_command
 };
 
+/* Aliases provide a mechanism to allow compatibility with old command
+ * names (such as "retrace") for current commands (such as the replay
+ * command). */
+typedef struct {
+    const char *name;
+    const Command *command;
+} Alias;
+
+static const Alias aliases[] = {
+    { "retrace", &retrace_command }
+};
+
 static void
 usage(void)
 {
@@ -151,6 +163,7 @@ main(int argc, char **argv)
 {
     const char *command_name;
     const Command *command;
+    const Alias *alias;
     int i;
 
     for (i = 1; i < argc; ++i) {
@@ -186,6 +199,13 @@ main(int argc, char **argv)
             return (command->function) (argc, argv);
     }
 
+    for (i = 0; i < ARRAY_SIZE(aliases); i++) {
+        alias = &aliases[i];
+
+        if (strcmp(command_name, alias->name) == 0)
+            return (alias->command->function) (argc, argv);
+    }
+
     std::cerr << "Error: unknown command " << command_name
               << " (see \"apitrace help\").\n";