#include #include "cargs/cargs.h" #include "options.h" #include "logging.h" static struct cag_option options[] = { { .identifier = 'q', .access_letters = "q", .access_name = NULL, .value_name = NULL, .description = "Decrease output verbosity (-qqq suppresses even fatal errors)", }, { .identifier = 'v', .access_letters = "v", .access_name = NULL, .value_name = NULL, .description = "Increase output verbosity (-vvv displays every log message)", }, { .identifier = 'c', .access_letters = "c", .access_name = "config", .value_name = "CONF_FILE", .description = "Specify configuration file to read (default: config.lua)", }, { .identifier = 's', .access_letters = "s", .access_name = "script", .value_name = "SCRIPT_FILE", .description = "Override the built-in build script", }, { .identifier = 'h', .access_letters = "h", .access_name = "help", .value_name = NULL, .description = "Print this help message and exit", }, }; static void print_usage(const char *progname) { printf("Usage: %s [OPTIONS]\n", progname); cag_option_print(options, CAG_ARRAY_SIZE(options), stdout); } int parse_options(struct argent_options *opts, int argc, char **argv) { opts->log_level = WARN; opts->conf_filename = "config.lua"; opts->script_filename = NULL; char opt; cag_option_context context; cag_option_prepare(&context, options, CAG_ARRAY_SIZE(options), argc, argv); while (cag_option_fetch(&context)) { opt = cag_option_get(&context); switch (opt) { case 'q': opts->log_level -= 1; break; case 'v': opts->log_level += 1; break; case 'c': opts->conf_filename = cag_option_get_value(&context); break; case 's': opts->script_filename = cag_option_get_value(&context); break; case 'h': print_usage(argv[0]); return 2; default: print_usage(argv[0]); return 1; } } // ew, globals (sorry) argent_log_level = opts->log_level; return 0; }