diff options
author | sanine <sanine.not@pm.me> | 2023-03-24 17:10:50 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-03-24 17:10:50 -0500 |
commit | 3ecb029fedcf03d3d9eec193d91d1ed1bc6dc130 (patch) | |
tree | 61637dd67e63f83c8c019cf8cfe20c503bf9fbb2 /src/options/options.c | |
parent | a2fcdef91e1e839e55d0db295abe80961a8a2dc0 (diff) |
add verbosity & working directory options
Diffstat (limited to 'src/options/options.c')
-rw-r--r-- | src/options/options.c | 46 |
1 files changed, 46 insertions, 0 deletions
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,10 +1,18 @@ #include <stdio.h> #include <cargs.h> #include <common.h> +#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", .access_name = "script", @@ -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; } } |