[waffle] [PATCH 1/2] utils/wflinfo: add --help parameter

Jordan Justen jordan.l.justen at intel.com
Wed Jan 29 11:40:58 PST 2014


--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 at intel.com>
---
 man/wflinfo.1.xml   |  8 ++++++++
 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 ff50d2e..5fcb157 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;
-- 
1.8.5.3



More information about the waffle mailing list