From: Timo Kokkonen Date: Mon, 7 Oct 2013 17:36:53 +0000 (+0300) Subject: options: Add help X-Git-Url: http://git.itanic.dy.fi/?p=log-plotter;a=commitdiff_plain;h=f41a6b795d8725597d5aaff4697571226364587c options: Add help Keep the users happy by letting them know how to use this damn thing. Signed-off-by: Timo Kokkonen --- diff --git a/options.c b/options.c index 28021f7..706d855 100644 --- 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; }