Skip to content

Commit

Permalink
Added command-line options to change the verbosity level
Browse files Browse the repository at this point in the history
  • Loading branch information
Snaipe committed Mar 9, 2015
1 parent 9dd534f commit e0eb661
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
#define _GNU_SOURCE
#include <criterion/criterion.h>
#include <criterion/logging.h>
#include <stdio.h>
#include <getopt.h>

# 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();
}

0 comments on commit e0eb661

Please sign in to comment.