From 646a00d12f31f75fa444d356a667fd64bd0ec323 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Sun, 30 Oct 2011 14:07:20 +0000 Subject: [PATCH] Tweak help output. * accept "apitrace dump --help" as help. * list commands in "apitrace help" too. * tweak whitespace. --- cli/cli.hpp | 5 +---- cli/cli_dump.cpp | 21 +++++++++++---------- cli/cli_main.cpp | 46 +++++++++++++++++++++++++++------------------- 3 files changed, 39 insertions(+), 33 deletions(-) diff --git a/cli/cli.hpp b/cli/cli.hpp index 8e43277..1bdc689 100644 --- a/cli/cli.hpp +++ b/cli/cli.hpp @@ -31,12 +31,9 @@ #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_ */ diff --git a/cli/cli_dump.cpp b/cli/cli_dump.cpp index fcc08f7..3a428db 100644 --- a/cli/cli_dump.cpp +++ b/cli/cli_dump.cpp @@ -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] ..." - "\n\n\t" - APITRACE_DUMP_SYNOPSIS - "\n\n\t" - "Supports the following options:\n\t" - "\t--color=\n\t" - "\t--colour= Colored syntax highlighting\n\t" - "\t WHEN is 'auto', 'always', or 'never'\n"; + std::cout << "usage: apitrace dump [OPTIONS] ...\n" + APITRACE_DUMP_SYNOPSIS "\n" + "\n" + " --color=\n" + " --colour= 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; } } diff --git a/cli/cli_main.cpp b/cli/cli_main.cpp index 944d7de..e96673a 100644 --- a/cli/cli_main.cpp +++ b/cli/cli_main.cpp @@ -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 << " []" - "\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 []\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 [ ...]\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 [ ...]\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 \" 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; } } -- 2.7.4