blob: cf93588f1c2df5ebf5a7cce7cff52ad4bddeffbd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#include <stdio.h>
#include <unistd.h> /* todo: create windows-compatible alternative */
#include "options/honey_options.h"
static void print_usage(const char *program_name)
{
printf("Usage: %s [OPTIONS]\n"
" -v Increase output verbosity (-vvv displays every log message)\n"
" -q Decrease output verbosity (-qqq suppresses even fatal errors)\n"
" -h Print this help message and exit\n"
" -s SCRIPT Load SCRIPT as the entry point instead of 'main.lua'\n",
program_name);
}
int parse_options(struct honey_options *opts, int argc, char **argv)
{
opts->main_script = "main.lua";
opts->log_level = WARN;
opts->display_help = 0;
int opt;
const char *flags = "hqvs:";
while ((opt = getopt(argc, argv, flags)) != -1) {
switch (opt) {
case 'q':
opts->log_level -= 1;
break;
case 'v':
opts->log_level += 1;
break;
case 'h':
print_usage(argv[0]);
opts->display_help = 1;
return 1;
case 's':
opts->main_script = optarg;
break;
default:
print_usage(argv[0]);
return 0;
}
}
honey_log_set_level(opts->log_level);
honey_log_set_file(stderr);
return 1;
}
|