]> git.cworth.org Git - apitrace/commitdiff
Tweak help output.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 30 Oct 2011 14:07:20 +0000 (14:07 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 30 Oct 2011 14:07:20 +0000 (14:07 +0000)
* accept "apitrace dump --help" as help.
* list commands in "apitrace help" too.
* tweak whitespace.

cli/cli.hpp
cli/cli_dump.cpp
cli/cli_main.cpp

index 8e43277422f1a8883897ec3680288f2844411ad2..1bdc689b392f142858b4875d948312125e678801 100644 (file)
 #define APITRACE_DUMP_SYNOPSIS "Dump given trace(s) to standard output."
 
 void
-apitrace_dump_usage(const char *argv0);
+apitrace_dump_usage(void);
 
 int
 apitrace_dump_command(int argc, char *argv[], int first_command_arg);
 
-void
-usage(void);
-
 #endif /* _APITRACE_CLI_HPP_ */
index fcc08f74bc9bdc430661fe7b3b25d73d7dfb1b2f..3a428dbb7909456221dc147f5a142b5f490dcc6b 100644 (file)
@@ -38,16 +38,14 @@ enum ColorOption {
 static ColorOption color = COLOR_OPTION_AUTO;
 
 void
-apitrace_dump_usage(const char *argv0)
+apitrace_dump_usage(void)
 {
-    std::cout << argv0 << " [OPTIONS] <trace-file>..."
-        "\n\n\t"
-        APITRACE_DUMP_SYNOPSIS
-        "\n\n\t"
-        "Supports the following options:\n\t"
-       "\t--color=<WHEN>\n\t"
-       "\t--colour=<WHEN>     Colored syntax highlighting\n\t"
-       "\t                    WHEN is 'auto', 'always', or 'never'\n";
+    std::cout << "usage: apitrace dump [OPTIONS] <trace-file>...\n"
+        APITRACE_DUMP_SYNOPSIS "\n"
+        "\n"
+        "    --color=<WHEN>\n"
+        "    --colour=<WHEN>     Colored syntax highlighting\n"
+        "                        WHEN is 'auto', 'always', or 'never'\n";
 }
 
 int
@@ -64,6 +62,9 @@ apitrace_dump_command(int argc, char *argv[], int first_arg_command)
 
         if (!strcmp(arg, "--")) {
             break;
+        } else if (!strcmp(arg, "--help")) {
+            apitrace_dump_usage();
+            return 0;
         } else if (!strcmp(arg, "--color=auto") ||
                    !strcmp(arg, "--colour=auto")) {
             color = COLOR_OPTION_AUTO;
@@ -79,7 +80,7 @@ apitrace_dump_command(int argc, char *argv[], int first_arg_command)
             color = COLOR_OPTION_NEVER;
         } else {
             std::cerr << "error: unknown option " << arg << "\n";
-            usage();
+            apitrace_dump_usage();
             return 1;
         }
     }
index 944d7dedc3a5908179b0865f5920dec067a5acaa..e96673ac70e251442e6bd1f20e430dccc164269f 100644 (file)
@@ -27,7 +27,7 @@
 
 
 /*
- * Top-level application for accessing most all apitrace
+ * Top-level application for accessing almost of apitrace
  * functionality.
  */
 
@@ -40,7 +40,7 @@
 
 #define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))
 
-typedef void (*command_usage_t) (const char *argv0);
+typedef void (*command_usage_t) (void);
 typedef int (*command_function_t) (int argc, char *argv[], int first_command_arg);
 
 typedef struct {
@@ -52,15 +52,16 @@ typedef struct {
 
 #define APITRACE_HELP_SYNOPSIS "Print detailed help for the given command."
 
+static void list_commands(void);
+
 static void
-apitrace_help_usage(const char *argv0)
+apitrace_help_usage()
 {
-    std::cout << argv0 << " [<command>]"
-        "\n\n\t"
-        APITRACE_HELP_SYNOPSIS
-        "\n\n\t"
-        "Except in this case, where this is all the help you will get."
-        "\n\n";
+    std::cout << "usage: apitrace help [<command>]\n"
+        APITRACE_HELP_SYNOPSIS "\n"
+        "\n";
+
+    list_commands();
 }
 
 static int
@@ -77,15 +78,23 @@ static Command commands[] = {
       apitrace_help_command }
 };
 
-void
+static void
 usage(void)
 {
+    std::cout <<
+        "Usage: apitrace <command> [<args> ...]\n"
+        "Top-level command line frontend to apitrace.\n"
+        "\n";
+
+    list_commands();
+}
+
+static void
+list_commands(void) {
     Command *command;
     int i, max_width = 0;
 
-    std::cout <<
-        "Usage: apitrace <command> [<args> ...]\n\n"
-        "The available commands are as follows:\n\n";
+    std::cout << "The available commands are as follows:\n\n";
 
     std::cout << std::setiosflags(std::ios::left);
 
@@ -98,7 +107,7 @@ usage(void)
     for (i = 0; i < ARRAY_SIZE(commands); i++) {
         command = &commands[i];
 
-        std::cout << " " << std::setw(max_width+2) << command->name
+        std::cout << "    " << std::setw(max_width+2) << command->name
                   << " " << command->synopsis << "\n";
     }
 
@@ -106,14 +115,15 @@ usage(void)
         "Use \"apitrace help <command>\" for more details on each command.\n";
 }
 
+
 static int
 apitrace_help_command(int argc, char *argv[], int first_arg_command)
 {
     Command *command;
     int i;
 
-    if(first_arg_command == argc) {
-        usage();
+    if (first_arg_command == argc) {
+        apitrace_help_usage();
         return 0;
     }
 
@@ -123,9 +133,7 @@ apitrace_help_command(int argc, char *argv[], int first_arg_command)
         command = &commands[i];
 
         if (strcmp(command_name, command->name) == 0) {
-            std::cout << "Help for \"apitrace " << command_name << "\":\n\n";
-            (command->usage) ("apitrace");
-
+            (command->usage) ();
             return 0;
         }
     }