summaryrefslogtreecommitdiff
path: root/src/options/options.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/options/options.c')
-rw-r--r--src/options/options.c46
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;
}
}