]> git.itanic.dy.fi Git - log-plotter/commitdiff
options: Add help
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Mon, 7 Oct 2013 17:36:53 +0000 (20:36 +0300)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Mon, 7 Oct 2013 17:36:53 +0000 (20:36 +0300)
Keep the users happy by letting them know how to use this damn thing.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
options.c

index 28021f7b4a9a6a9c15a37b6f32f0264dce20e219..706d8556981ad73bd018cd1aea4d68ebdc622018 100644 (file)
--- a/options.c
+++ b/options.c
@@ -6,6 +6,20 @@
 #include "options.h"
 #include "debug.h"
 
+void print_help_and_die(const char *exec_name)
+{
+       pr_info("Usage: %s [option]\n", exec_name);
+       pr_info("  -d, --device=DEVICE     path to the serial device\n");
+       pr_info("                          default: /dev/ttyUSB0\n");
+       pr_info("  -b, --baud=BAUD         device baud rate, default 128000\n");
+       pr_info("  -o, --output            logfile path, stdout only if omited\n");
+       pr_info("  -v, --verbose           increase verbosity\n");
+       pr_info("  -q, --quiet             decrease verbosity\n");
+       pr_info("  -h, --help              show this help\n");
+
+       exit(0);
+}
+
 static void set_default_options(struct plotter_options *opts)
 {
        bzero(opts, sizeof(*opts));
@@ -23,8 +37,9 @@ int read_args(int argc, char *argv[], struct plotter_options *opts)
                { .val = 'b', .name = "baud", .has_arg = 1 },
                { .val = 'v', .name = "verbose", .has_arg = 2 },
                { .val = 'q', .name = "quiet", },
+               { .val = 'h', .name = "help", },
        };
-       char short_options[] = "d:o:b:vq";
+       char short_options[] = "d:o:b:vqh";
 
        set_default_options(opts);
 
@@ -53,6 +68,9 @@ int read_args(int argc, char *argv[], struct plotter_options *opts)
                        trace_level--;
                        pr_debug("Degreased trace level to %d\n", trace_level);
                        break;
+               case 'h':
+                       print_help_and_die(argv[0]);
+                       break;
                case '?':
                        return -1;
                }