Commit 40ed1153 authored by Samir Halilcevic's avatar Samir Halilcevic

Remove space separated config-file value

parent 7ac22638
...@@ -104,11 +104,10 @@ private: ...@@ -104,11 +104,10 @@ private:
mutable void* value_; mutable void* value_;
}; };
/// Finds `config_option` string with a matching long name in the string /// Finds `config_option` string with a matching long name in the argument list
/// argument list [`first`, `last`). Returns an `argument_iterator` to the /// [`first`, `last`). Returns an `iterator` to the matching location and a
/// matching location and a `string_view` of the option value if the entry is /// `string_view` of the option value if the entry is found, or a `iterator`
/// found, or a `arugment_iterator` to `last` with an empty `string_view` /// to `last` with an empty `string_view` otherwise.
/// otherwise.
std::pair<std::vector<std::string>::const_iterator, std::string_view> std::pair<std::vector<std::string>::const_iterator, std::string_view>
find_by_long_name(const config_option& x, find_by_long_name(const config_option& x,
std::vector<std::string>::const_iterator first, std::vector<std::string>::const_iterator first,
......
...@@ -470,7 +470,11 @@ actor_system_config::extract_config_file_path(string_list& args) { ...@@ -470,7 +470,11 @@ actor_system_config::extract_config_file_path(string_list& args) {
std::string{}}; std::string{}};
} else { } else {
auto path_str = std::string{path.begin(), path.end()}; auto path_str = std::string{path.begin(), path.end()};
if (i->find('=') != std::string::npos) {
args.erase(i); args.erase(i);
} else {
args.erase(i, i + 2);
}
config_value val{path_str}; config_value val{path_str};
if (auto err = ptr->sync(val); !err) { if (auto err = ptr->sync(val); !err) {
put(content, "config-file", std::move(val)); put(content, "config-file", std::move(val));
......
...@@ -133,7 +133,7 @@ std::string_view config_option::buf_slice(size_t from, ...@@ -133,7 +133,7 @@ std::string_view config_option::buf_slice(size_t from,
return {buf_.get() + from, to - from}; return {buf_.get() + from, to - from};
} }
// TODO: consider deprecating this // TODO: consider using `config_option_set` and deprecating this
std::pair<std::vector<std::string>::const_iterator, std::string_view> std::pair<std::vector<std::string>::const_iterator, std::string_view>
find_by_long_name(const config_option& x, find_by_long_name(const config_option& x,
std::vector<std::string>::const_iterator first, std::vector<std::string>::const_iterator first,
...@@ -157,7 +157,7 @@ find_by_long_name(const config_option& x, ...@@ -157,7 +157,7 @@ find_by_long_name(const config_option& x,
str.remove_prefix(1); str.remove_prefix(1);
return {first, str}; return {first, str};
} else if (str.empty() && (first + 1) != last) { } else if (str.empty() && (first + 1) != last) {
// Get the next argument as value // Get the next argument the value
++first; ++first;
return {first, std::string_view{*first}}; return {first, std::string_view{*first}};
} else { } else {
......
...@@ -167,18 +167,16 @@ auto config_option_set::parse(settings& config, argument_iterator first, ...@@ -167,18 +167,16 @@ auto config_option_set::parse(settings& config, argument_iterator first,
} }
} }
}; };
// We loop over the first N-1 values, because we always consider two
// arguments at once.
for (auto i = first; i != last;) { for (auto i = first; i != last;) {
if (i->size() < 2) if (i->size() < 2)
return {pec::not_an_option, i}; return {pec::not_an_option, i};
if (*i == "--") if (*i == "--")
return {pec::success, std::next(first)}; return {pec::success, std::next(first)};
if (i->compare(0, 2, "--") == 0) { if (i->compare(0, 2, "--") == 0) {
// Long options cone in three variaties: // Long options come in three varieties:
// syntax "--<name>=<value>" formated as a single single argument, // "--<name>", config option is a boolean flag
// sytnax "--<name> <value>", comes as two arguments // "--<name>=<value>", formatted as a single argument with the value,
// special case "--<name>", boolean flag // "--<name> <value>", formatted as two arguments,
const auto npos = std::string::npos; const auto npos = std::string::npos;
auto assign_op = i->find('='); auto assign_op = i->find('=');
auto name = assign_op == npos ? i->substr(2) auto name = assign_op == npos ? i->substr(2)
......
...@@ -55,7 +55,6 @@ struct fixture { ...@@ -55,7 +55,6 @@ struct fixture {
void parse(const char* file_content, string_list args = {}) { void parse(const char* file_content, string_list args = {}) {
cfg.clear(); cfg.clear();
cfg.remainder.clear();
std::istringstream conf{file_content}; std::istringstream conf{file_content};
if (auto err = cfg.parse(std::move(args), conf)) if (auto err = cfg.parse(std::move(args), conf))
CAF_FAIL("parse() failed: " << err); CAF_FAIL("parse() failed: " << err);
...@@ -150,6 +149,21 @@ CAF_TEST(file input overrides defaults but CLI args always win) { ...@@ -150,6 +149,21 @@ CAF_TEST(file input overrides defaults but CLI args always win) {
CHECK_EQ(content(cfg), res); CHECK_EQ(content(cfg), res);
} }
CAF_TEST(parsing - with config file cli option) {
MESSAGE("Try opening non-existent config file");
cfg.clear();
auto err = cfg.parse(string_list{"--config-file=test-me"});
CHECK_EQ(err, caf::sec::cannot_open_file);
CHECK(cfg.remainder.empty());
CHECK_EQ(get_or(cfg, "config-file", ""), "test-me");
cfg.clear();
err = cfg.parse(string_list{"--config-file", "test-me"});
CHECK_EQ(err, caf::sec::cannot_open_file);
CHECK(cfg.remainder.empty());
CHECK_EQ(get_or(cfg, "config-file", ""), "test-me");
}
// Checks whether both a synced variable and the corresponding entry in // Checks whether both a synced variable and the corresponding entry in
// content(cfg) are equal to `value`. // content(cfg) are equal to `value`.
#define CHECK_SYNCED(var, ...) \ #define CHECK_SYNCED(var, ...) \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment