Skip to content
Snippets Groups Projects
Commit 65a6ea8c authored by Amna Snene's avatar Amna Snene
Browse files

tools: fix dnc argument

Change-Id: I12ac7e224bac1f8225f50d9398a9ff755e73ba29
parent 77bb5858
Branches
No related tags found
No related merge requests found
...@@ -46,7 +46,7 @@ struct dhtnc_params ...@@ -46,7 +46,7 @@ struct dhtnc_params
}; };
static const constexpr struct option long_options[] = {{"help", no_argument, nullptr, 'h'}, static const constexpr struct option long_options[] = {{"help", no_argument, nullptr, 'h'},
{"version", no_argument, nullptr, 'V'}, {"version", no_argument, nullptr, 'v'},
{"port", required_argument, nullptr, 'p'}, {"port", required_argument, nullptr, 'p'},
{"ip", required_argument, nullptr, 'i'}, {"ip", required_argument, nullptr, 'i'},
{"listen", no_argument, nullptr, 'l'}, {"listen", no_argument, nullptr, 'l'},
...@@ -63,13 +63,12 @@ parse_args(int argc, char** argv) ...@@ -63,13 +63,12 @@ parse_args(int argc, char** argv)
{ {
dhtnc_params params; dhtnc_params params;
int opt; int opt;
while ((opt = getopt_long(argc, argv, "hVlw:r:u:t:I:b:p:i:", long_options, nullptr)) != -1) { while ((opt = getopt_long(argc, argv, "hvlw:r:u:t:I:b:p:i:", long_options, nullptr)) != -1) {
// fmt::print("opt: {} {}\n", opt, optarg);
switch (opt) { switch (opt) {
case 'h': case 'h':
params.help = true; params.help = true;
break; break;
case 'V': case 'v':
params.version = true; params.version = true;
break; break;
case 'p': case 'p':
...@@ -106,7 +105,7 @@ parse_args(int argc, char** argv) ...@@ -106,7 +105,7 @@ parse_args(int argc, char** argv)
} }
// If not listening, the peer_id argument is required // If not listening, the peer_id argument is required
if (!params.listen) { if (!params.listen && !params.help && !params.version) {
if (optind < argc) { if (optind < argc) {
params.peer_id = dht::InfoHash(argv[optind]); params.peer_id = dht::InfoHash(argv[optind]);
optind++; // Move to the next argument optind++; // Move to the next argument
...@@ -152,9 +151,31 @@ setSipLogLevel() ...@@ -152,9 +151,31 @@ setSipLogLevel()
int int
main(int argc, char** argv) main(int argc, char** argv)
{ {
fmt::print("dnc 1.0\n");
setSipLogLevel(); setSipLogLevel();
auto params = parse_args(argc, argv); auto params = parse_args(argc, argv);
if (params.help ){
fmt::print("Usage: dnc [options] [PEER_ID]\n"
"\nOptions:\n"
" -h, --help Show this help message and exit.\n"
" -v, --version Display the program version.\n"
" -p, --port Specify the port option with an argument.\n"
" -i, --ip Specify the ip option with an argument.\n"
" -l, --listen Start the program in listen mode.\n"
" -b, --bootstrap Specify the bootstrap option with an argument.\n"
" -I, --id_path Specify the id_path option with an argument.\n"
" -t, --turn_host Specify the turn_host option with an argument.\n"
" -u, --turn_user Specify the turn_user option with an argument.\n"
" -w, --turn_pass Specify the turn_pass option with an argument.\n"
" -r, --turn_realm Specify the turn_realm option with an argument.\n");
return EXIT_SUCCESS;
}
if (params.version) {
fmt::print("dnc v1.0\n");
return EXIT_SUCCESS;
}
fmt::print("dnc 1.0\n");
auto identity = dhtnet::loadIdentity(params.path); auto identity = dhtnet::loadIdentity(params.path);
fmt::print("Loaded identity: {} from {}\n", identity.second->getId(), params.path); fmt::print("Loaded identity: {} from {}\n", identity.second->getId(), params.path);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment