--- a/src/CLIParser.h Fri Jul 29 18:03:49 2022 +0200
+++ b/src/CLIParser.h Sat Jul 30 00:16:40 2022 +0200
@@ -18,6 +18,7 @@
#include <vector>
#include <iostream>
+#include <codecvt>
#include <relpipe/common/type/typedefs.h>
#include <relpipe/cli/CLI.h>
@@ -31,6 +32,7 @@
class CLIParser {
private:
+ std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings.
relpipe::common::type::StringX readNext(const std::vector<relpipe::common::type::StringX>& arguments, int& i) {
if (i < arguments.size()) return arguments[i++];
@@ -46,6 +48,13 @@
else throw relpipe::cli::RelpipeCLIException(L"Unable to parse boolean value: " + value + L" (expecting true or false)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
}
+ void setIfMissing(std::vector<Configuration::SocketOption>& options, const std::string& name, const std::string& value) {
+ auto n = convertor.from_bytes(name);
+ auto v = convertor.from_bytes(value);
+ for (auto o : options) if (o.name == n) return;
+ options.push_back({n, v});
+ }
+
public:
static const relpipe::common::type::StringX OPTION_RELATION;
@@ -61,7 +70,8 @@
if (option == OPTION_RELATION) {
c.relation = readNext(arguments, i);
} else if (option == OPTION_CONNECTION_STRING) {
- c.connectionString = readNext(arguments, i);
+ auto connectionString = readNext(arguments, i);
+ // FIXME: parse connection string and convert it to options
} else if (option == OPTION_CONNECTION_OPTION) {
auto name = readNext(arguments, i);
auto value = readNext(arguments, i);
@@ -69,6 +79,13 @@
} else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
}
+ using namespace options;
+ setIfMissing(c.options, OPTION_PROTOCOL, PROTOCOL_UDP);
+ setIfMissing(c.options, OPTION_ROLE, ROLE_CLIENT);
+ setIfMissing(c.options, OPTION_MODE, MODE_DATAGRAM);
+ setIfMissing(c.options, OPTION_HOST, "127.0.0.1");
+ setIfMissing(c.options, OPTION_PORT, "64000");
+
return c;
}