Improve command line parsing
Improve command line argument parser. This will make it easier to add code to read command line options (which previously weren't available).
This commit is contained in:
parent
3d44312e93
commit
8b07320f76
28
src/main.cxx
28
src/main.cxx
|
@ -47,25 +47,25 @@ void printIntro() {
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
printIntro();
|
printIntro();
|
||||||
|
|
||||||
std::string path;
|
std::string path = "";
|
||||||
|
|
||||||
// Parse cmdline options
|
// Parse cmdline options
|
||||||
switch (argc) {
|
for (int argi = 1; argi < argc; argi++) {
|
||||||
case 1:
|
if (argv[argi][0] == '-') {
|
||||||
path = ".";
|
// This is a cmdline option (starts with a dash).
|
||||||
std::cout << "Assuming working directory is \".\""
|
|
||||||
<< std::endl;
|
} else if (path == "") {
|
||||||
break;
|
path = argv[argi];
|
||||||
case 2:
|
} else {
|
||||||
path = argv[1];
|
std::cerr << "error: website directory was already " <<
|
||||||
std::cout << "Using specified directory: "
|
"provided (`" << path << "'), refusing to continue with `" <<
|
||||||
<< path << std::endl;
|
argv[argi] << "'.\n";
|
||||||
break;
|
|
||||||
default:
|
|
||||||
printUsage(argv[0]);
|
printUsage(argv[0]);
|
||||||
exit(RETURN_FAILED_INVALID_SYNTAX);
|
exit(RETURN_FAILED_INVALID_SYNTAX);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Using specified directory: " << path << "\n";
|
||||||
|
|
||||||
SwgContext ctx;
|
SwgContext ctx;
|
||||||
parse_config(&ctx, path);
|
parse_config(&ctx, path);
|
||||||
|
|
Loading…
Reference in New Issue