From b6991bb59a844acfbf9b67032f192469e80cc397 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 9 Jan 2023 09:13:00 -0800 Subject: [PATCH 1/3] lokinet.cpp CLI and logic fixes - added single dash to one letter flags to fix CLI incorrectconstruction error - fixed generate file error --- daemon/lokinet-vpn.cpp | 8 ++++++-- daemon/lokinet.cpp | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/daemon/lokinet-vpn.cpp b/daemon/lokinet-vpn.cpp index b6512ed1a..7fd6a3c4e 100644 --- a/daemon/lokinet-vpn.cpp +++ b/daemon/lokinet-vpn.cpp @@ -108,11 +108,11 @@ main(int argc, char* argv[]) command_line_options options{}; // flags: boolean values in command_line_options struct - cli.add_flag("v,--verbose", options.verbose, "Verbose"); + cli.add_flag("-v,--verbose", options.verbose, "Verbose"); cli.add_flag("--up", options.vpnUp, "Put VPN up"); cli.add_flag("--down", options.vpnDown, "Put VPN down"); cli.add_flag("--status", options.printStatus, "Print VPN status and exit"); - cli.add_flag("k,--kill", options.killDaemon, "Kill lokinet daemon"); + cli.add_flag("-k,--kill", options.killDaemon, "Kill lokinet daemon"); // options: string values in command_line_options struct cli.add_option("--exit", options.exitAddress, "Specify exit node address")->capture_default_str(); @@ -156,6 +156,10 @@ main(int argc, char* argv[]) case 0: return exit_error(3, "One of --up/--down/--status/--kill must be specified"); case 1: + break; + case 2: + case 3: + case 4: return exit_error(3, "Only one of --up/--down/--status/--kill may be specified"); default: break; diff --git a/daemon/lokinet.cpp b/daemon/lokinet.cpp index 454d18bb8..76587130c 100644 --- a/daemon/lokinet.cpp +++ b/daemon/lokinet.cpp @@ -34,10 +34,13 @@ namespace bool generate = false; bool router = false; bool force = false; + bool config = false; bool configOnly = false; bool overwrite = false; // string options + // TODO: change this to use a std::filesystem::path once we stop using ghc::filesystem on some + // platforms std::string configPath; // windows options @@ -369,10 +372,10 @@ namespace // flags: boolean values in command_line_options struct cli.add_flag("--version", options.version, "Lokinet version"); - cli.add_flag("g,--generate", options.generate, "Generate default configuration and exit"); + cli.add_flag("-g,--generate", options.generate, "Generate default configuration and exit"); cli.add_flag( - "r,--router", options.router, "Run lokinet in routing mode instead of client-only mode"); - cli.add_flag("f,--force", options.force, "Force writing config even if file exists"); + "-r,--router", options.router, "Run lokinet in routing mode instead of client-only mode"); + cli.add_flag("-f,--force", options.force, "Force writing config even if file exists"); // options: string cli.add_option("--config", options.configPath, "Path to lokinet.ini configuration file") @@ -417,7 +420,12 @@ namespace } } - if (options.configOnly) + if (options.generate) + { + options.configOnly = true; + } + + if (not options.configPath.empty()) { configFile = options.configPath; } From 26beebca97d66a87d4cb8f5b67d44b242c0e7797 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 9 Jan 2023 11:43:25 -0800 Subject: [PATCH 2/3] logic fix, commit to be stashed --- daemon/lokinet-vpn.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/daemon/lokinet-vpn.cpp b/daemon/lokinet-vpn.cpp index 7fd6a3c4e..c1c78f4d1 100644 --- a/daemon/lokinet-vpn.cpp +++ b/daemon/lokinet-vpn.cpp @@ -157,12 +157,8 @@ main(int argc, char* argv[]) return exit_error(3, "One of --up/--down/--status/--kill must be specified"); case 1: break; - case 2: - case 3: - case 4: - return exit_error(3, "Only one of --up/--down/--status/--kill may be specified"); default: - break; + return exit_error(3, "Only one of --up/--down/--status/--kill may be specified"); } if (options.vpnUp and options.exitAddress.empty()) From ea740ffd79dcdb971d62c3c3738a068f419c0834 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 10 Jan 2023 06:35:41 -0800 Subject: [PATCH 3/3] options.overwrite and options.force are redundant given refactor. they are now combined --- daemon/lokinet.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/daemon/lokinet.cpp b/daemon/lokinet.cpp index 76587130c..d9413d693 100644 --- a/daemon/lokinet.cpp +++ b/daemon/lokinet.cpp @@ -33,7 +33,6 @@ namespace bool version = false; bool generate = false; bool router = false; - bool force = false; bool config = false; bool configOnly = false; bool overwrite = false; @@ -375,7 +374,7 @@ namespace cli.add_flag("-g,--generate", options.generate, "Generate default configuration and exit"); cli.add_flag( "-r,--router", options.router, "Run lokinet in routing mode instead of client-only mode"); - cli.add_flag("-f,--force", options.force, "Force writing config even if file exists"); + cli.add_flag("-f,--force", options.overwrite, "Force writing config even if file exists"); // options: string cli.add_option("--config", options.configPath, "Path to lokinet.ini configuration file")