Make help more useful

pull/546/head
Michael 5 years ago
parent c5c64731e7
commit 5589d9b471
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C

@ -27,14 +27,6 @@ handle_signal(int sig)
llarp_main_signal(ctx, sig); llarp_main_signal(ctx, sig);
} }
int
printHelp(const char *argv0, int code = 1)
{
std::cout << "usage: " << argv0 << " [-h] [-v] [-g|-c] config.ini"
<< std::endl;
return code;
}
#ifdef _WIN32 #ifdef _WIN32
int int
startWinsock() startWinsock()
@ -117,7 +109,7 @@ main(int argc, char *argv[])
("config","path to configuration file", cxxopts::value<std::string>()); ("config","path to configuration file", cxxopts::value<std::string>());
options.parse_positional("config"); options.parse_positional("config");
// clang-format on // clang-format on
bool genconfigOnly = false; bool genconfigOnly = false;
bool asRouter = false; bool asRouter = false;
@ -136,7 +128,8 @@ main(int argc, char *argv[])
if(result.count("help")) if(result.count("help"))
{ {
return printHelp(argv[0], 0); std::cout << options.help() << std::endl;
return 0;
} }
if(result.count("generate") > 0) if(result.count("generate") > 0)
@ -154,7 +147,7 @@ main(int argc, char *argv[])
asRouter = true; asRouter = true;
} }
if(result.count("config") > 0) if(result.count("config") > 0)
{ {
auto arg = result["config"].as< std::string >(); auto arg = result["config"].as< std::string >();
if(!arg.empty()) if(!arg.empty())
@ -163,10 +156,11 @@ main(int argc, char *argv[])
} }
} }
} }
catch (const cxxopts::option_not_exists_exception& ex) catch(const cxxopts::option_not_exists_exception &ex)
{ {
std::cerr << ex.what(); std::cerr << ex.what();
return printHelp(argv[0]); std::cout << options.help() << std::endl;
return 1;
} }
if(!conffname.empty()) if(!conffname.empty())
@ -186,8 +180,8 @@ main(int argc, char *argv[])
// does this file exist? // does this file exist?
if(genconfigOnly) if(genconfigOnly)
{ {
if(!llarp_ensure_config(conffname.c_str(), basedir.string().c_str(), overWrite, if(!llarp_ensure_config(conffname.c_str(), basedir.string().c_str(),
asRouter)) overWrite, asRouter))
return 1; return 1;
} }
else else

Loading…
Cancel
Save