From 35f3eeef6e18f2c76d112298e52ce3c662ce0591 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Mon, 9 Mar 2015 02:37:55 +0100 Subject: [PATCH] Added command-line options to change the verbosity level --- src/main.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index bcaac01..789f190 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,34 @@ +#define _GNU_SOURCE #include +#include +#include +#include + +# define USAGE \ + "usage: %s OPTIONS\n" \ + "options: \n" \ + " -h or --help: prints this message\n" \ + " --verbose [level]: sets verbosity to level\n" + +int print_usage(char *progname) { + fprintf(stderr, USAGE, progname); + return 0; +} + +int main(int argc, char *argv[]) { + static struct option opts[] = { + {"verbose", optional_argument, 0, 'v'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0 } + }; + + for (int c; (c = getopt_long(argc, argv, "h", opts, NULL)) != -1;) { + switch (c) { + case 'v': logging_threshold = atoi(optarg ?: "1"); break; + case 'h': + default : return print_usage(argv[0]); + } + } -int main(void) { return criterion_run_all_tests(); }