diff options
author | Jordan Justen <jordan.l.justen@intel.com> | 2014-01-29 11:40:58 -0800 |
---|---|---|
committer | Chad Versace <chad.versace@linux.intel.com> | 2014-02-07 09:45:28 -0800 |
commit | 3892eb001f2877b8c09cd2c2302328b77d0193bf (patch) | |
tree | 9af60b31277f4570490774daecb30899e87834e2 | |
parent | 3dd59c49d77b610a220b8fc3d4151e70a0a51280 (diff) |
wflinfo: add --help parameter
--help will cause wflinfo to print usage information to
stdout and exit with a return code of 0.
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
-rw-r--r-- | man/wflinfo.1.xml | 8 | ||||
-rw-r--r-- | src/utils/wflinfo.c | 20 |
2 files changed, 25 insertions, 3 deletions
diff --git a/man/wflinfo.1.xml b/man/wflinfo.1.xml index 1f81e73..e2a590d 100644 --- a/man/wflinfo.1.xml +++ b/man/wflinfo.1.xml @@ -146,6 +146,14 @@ </para> </listitem> </varlistentry> + <varlistentry> + <term><option>--help</option></term> + <listitem> + <para> + Print wflinfo usage information + </para> + </listitem> + </varlistentry> </variablelist> </refsect1> diff --git a/src/utils/wflinfo.c b/src/utils/wflinfo.c index 1a458ed..39fc44a 100644 --- a/src/utils/wflinfo.c +++ b/src/utils/wflinfo.c @@ -83,6 +83,9 @@ static const char *usage_message = " --debug-context\n" " Create a debug context.\n" "\n" + " --help\n" + " Print wflinfo usage information.\n" + "\n" "Examples:\n" " wflinfo --platform=glx --api=gl\n" " wflinfo --platform=x11_egl --api=gl --version=3.2 --profile=core\n" @@ -99,6 +102,7 @@ enum { OPT_VERBOSE = 'v', OPT_DEBUG_CONTEXT, OPT_FORWARD_COMPATIBLE, + OPT_HELP, }; static const struct option get_opts[] = { @@ -109,6 +113,7 @@ static const struct option get_opts[] = { { .name = "verbose", .has_arg = no_argument, .val = OPT_VERBOSE }, { .name = "debug-context", .has_arg = no_argument, .val = OPT_DEBUG_CONTEXT }, { .name = "forward-compatible", .has_arg = no_argument, .val = OPT_FORWARD_COMPATIBLE }, + { .name = "help", .has_arg = no_argument, .val = OPT_HELP }, { 0 }, }; @@ -133,6 +138,14 @@ error_printf(const char *fmt, ...) exit(EXIT_FAILURE); } + +static void __attribute__((noreturn)) +write_usage_and_exit(FILE *f, int exit_code) +{ + fprintf(f, "%s", usage_message); + exit(exit_code); +} + static void __attribute__((noreturn)) usage_error_printf(const char *fmt, ...) { @@ -149,9 +162,7 @@ usage_error_printf(const char *fmt, ...) fprintf(stderr, "\n"); fprintf(stderr, "\n"); - fprintf(stderr, "%s", usage_message); - - exit(EXIT_FAILURE); + write_usage_and_exit(stderr, EXIT_FAILURE); } static void @@ -363,6 +374,9 @@ parse_args(int argc, char *argv[], struct options *opts) case OPT_DEBUG_CONTEXT: opts->context_debug = true; break; + case OPT_HELP: + write_usage_and_exit(stdout, EXIT_SUCCESS); + break; default: abort(); loop_get_opt = false; |