From 3ecb029fedcf03d3d9eec193d91d1ed1bc6dc130 Mon Sep 17 00:00:00 2001 From: sanine Date: Fri, 24 Mar 2023 17:10:50 -0500 Subject: add verbosity & working directory options --- src/options/options.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/options/options.h | 2 ++ 2 files changed, 48 insertions(+) (limited to 'src/options') diff --git a/src/options/options.c b/src/options/options.c index cf2ae49..d2221aa 100644 --- a/src/options/options.c +++ b/src/options/options.c @@ -1,9 +1,17 @@ #include #include #include +#include "logging/logging.h" #include "options.h" static struct cag_option opts[] = { + { + .identifier = 'd', + .access_letters = "d", + .access_name = "directory", + .value_name = "WORKING_DIRECTORY", + .description = "Set the working directory for honey. (default: .)", + }, { .identifier = 's', .access_letters = "s", @@ -25,6 +33,20 @@ static struct cag_option opts[] = { .value_name = NULL, .description = "Shows this help message" }, + { + .identifier = 'v', + .access_letters = "v", + .access_name = NULL, + .value_name = NULL, + .description = "Increase verbosity (-vvv shows all messages)" + }, + { + .identifier = 'q', + .access_letters = "q", + .access_name = NULL, + .value_name = NULL, + .description = "Decrease verbosity (-qqq hides all messages)" + }, }; @@ -38,7 +60,9 @@ void print_help(char *program_name) enum outcomes_t parse_options(struct honey_options *options, int argc, char **argv) { /* default values */ + options->working_dir = NULL; options->script_file = "main.lua"; + options->log_level = HONEY_WARN; /* parse options */ char id; @@ -49,12 +73,22 @@ enum outcomes_t parse_options(struct honey_options *options, int argc, char **ar while(cag_option_fetch(&context)) { id = cag_option_get(&context); switch(id) { + /* set working directory */ + case 'd': + options->working_dir = cag_option_get_value(&context); + break; + + /* set main script */ case 's': options->script_file = cag_option_get_value(&context); break; + + /* print help information & exit */ case 'h': print_help(argv[0]); return EXIT_SUCCESS; + + /* print version information & exit */ case 'e': printf( "honey v%d.%d.%d -- %s\n", @@ -64,7 +98,19 @@ enum outcomes_t parse_options(struct honey_options *options, int argc, char **ar HONEY_VERSION_STR ); return EXIT_SUCCESS; + + /* verbosity options */ + case 'q': + options->log_level -= 1; + break; + case 'v': + options->log_level += 1; + break; + default: + int index = cag_option_get_index(&context); + fprintf(stderr, "unknown option: %s\n", argv[index-1]); + print_help(argv[0]); return EXIT_FAILURE; } } diff --git a/src/options/options.h b/src/options/options.h index cb07b1a..a7444f6 100644 --- a/src/options/options.h +++ b/src/options/options.h @@ -2,7 +2,9 @@ #define HONEY_OPTIONS_H struct honey_options { + const char *working_dir; const char *script_file; // main entry point + int log_level; }; enum outcomes_t { -- cgit v1.2.1