-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmdline_args.cpp
More file actions
60 lines (53 loc) · 1.5 KB
/
cmdline_args.cpp
File metadata and controls
60 lines (53 loc) · 1.5 KB
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
60
#include <unistd.h> //getopt
#include "cmdline_args.h"
namespace schrandr {
CmdLineOptions parseCmdlineArgs(int argc, char **argv) {
CmdLineOptions options;
char *confDir = nullptr;
bool hasConfDir = false;
int index;
int c;
while ((c = getopt (argc, argv, "ivhc:")) != -1) {
switch (c)
{
case 'i':
options.interactive = true;
break;
case 'v':
options.version = true;
break;
case 'h':
options.help = true;
case 'c': {
confDir = optarg;
hasConfDir = true;
}
case '?':
if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf (stderr,
"Unknown option character `\\x%x'.\n",
optopt);
default:
abort ();
}
}
for (index = optind; index < argc; index++)
printf ("Non-option argument %s\n", argv[index]);
if (hasConfDir) {
options.confDir = std::string(confDir);
}
return options;
}
void printHelp(std::ostream &out) {
out << "Possible flags:"
<< "\t-i\t\trun interactively, do not become a daemon\n"
<< "\t-v\t\tprint version info\n"
<< "\t-c DIR\t\tuse custom configuration directory"
<< "\t-h\t\tprint this help" << std::endl;
}
void printVersion(std::ostream &out) {
out << "Schrandr 0.0.0" << std::endl;
}
}