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
58
59
|
#include "command_line_options.h"
#include <getopt.h>
CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) {
// parse command line arguments
for (;;) {
static const struct option longOptions[] = {
{"config", required_argument, NULL, 'c'},
{"default", required_argument, NULL, 'd'},
{"pool", required_argument, NULL, 'P'},
{"path", required_argument, NULL, 'p'},
{"xpath", required_argument, NULL, 'x'},
{"size", required_argument, NULL, 's'},
{"version", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{0, 0, 0, 0}
};
int opt = getopt_long(argc, argv, "c:d:P:p:x:s:w:vhb", longOptions, NULL);
if (opt == -1) break;
switch (opt) {
case 'c':
options.insert("config", optarg);
break;
case 'd':
options.insert("default", optarg);
break;
case 'P':
options.insert("pool", optarg);
break;
case 'p':
options.insert("path", optarg);
break;
case 'x':
options.insert("xpath", optarg);
break;
case 's':
options.insert("size", optarg);
break;
case 'v':
options.insert("version", "version");
break;
case 'h':
options.insert("usage", "usage");
break;
case '?':
default:
options.insert("error", "error");
}
if (optind == argc - 1) {
options.insert("file", argv[optind]);
} else if (optind < argc - 1) {
options.insert("error", "error");
}
}
}
|