blob: fa6b9991d36810dec2bcebf237df227973e7139f (
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
56
57
|
#include <stdio.h>
#include <unistd.h>
#include "options.h"
#include "logging.h"
static void print_usage(const char *progname)
{
printf("Usage: %s [-c config_file] [-v[v[v]]] [-q[q[q]]] [-h] [-s script]\n"
" -v Increase output verbosity (-vvv displays every log message)\n"
" -q Decrease output verbosity (-qqq suppresses even fatal errors)\n"
" -c Specify configuration file to read (default 'config.lua')\n"
" -s Override the built-in Lua script\n"
" -h Print this help message and exit\n",
progname);
}
int parse_options(struct argent_options *opts, int argc, char **argv)
{
opts->log_level = WARN;
opts->conf_filename = "config.lua";
opts->script_filename = NULL;
int opt;
while ((opt = getopt(argc, argv, "hqvc:s:")) != -1) {
switch (opt) {
case 'q':
opts->log_level -= 1;
break;
case 'v':
opts->log_level += 1;
break;
case 'c':
opts->conf_filename = optarg;
break;
case 's':
opts->script_filename = optarg;
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;
}
|