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

Remove space separated config-file value

parent 7ac22638
......@@ -104,11 +104,10 @@ private:
mutable void* value_;
};
/// Finds `config_option` string with a matching long name in the string
/// argument list [`first`, `last`). Returns an `argument_iterator` to the
/// matching location and a `string_view` of the option value if the entry is
/// found, or a `arugment_iterator` to `last` with an empty `string_view`
/// otherwise.
/// Finds `config_option` string with a matching long name in the argument list
/// [`first`, `last`). Returns an `iterator` to the matching location and a
/// `string_view` of the option value if the entry is found, or a `iterator`
/// to `last` with an empty `string_view` otherwise.
std::pair<std::vector<std::string>::const_iterator, std::string_view>
find_by_long_name(const config_option& x,
std::vector<std::string>::const_iterator first,
......
......@@ -470,7 +470,11 @@ actor_system_config::extract_config_file_path(string_list& args) {
std::string{}};
} else {
auto path_str = std::string{path.begin(), path.end()};
args.erase(i);
if (i->find('=') != std::string::npos) {
args.erase(i);
} else {
args.erase(i, i + 2);
}
config_value val{path_str};
if (auto err = ptr->sync(val); !err) {
put(content, "config-file", std::move(val));
......
......@@ -133,7 +133,7 @@ std::string_view config_option::buf_slice(size_t 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>
find_by_long_name(const config_option& x,
std::vector<std::string>::const_iterator first,
......@@ -157,7 +157,7 @@ find_by_long_name(const config_option& x,
str.remove_prefix(1);
return {first, str};
} else if (str.empty() && (first + 1) != last) {
// Get the next argument as value
// Get the next argument the value
++first;
return {first, std::string_view{*first}};
} else {
......
......@@ -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;) {
if (i->size() < 2)
return {pec::not_an_option, i};
if (*i == "--")
return {pec::success, std::next(first)};
if (i->compare(0, 2, "--") == 0) {
// Long options cone in three variaties:
// syntax "--<name>=<value>" formated as a single single argument,
// sytnax "--<name> <value>", comes as two arguments
// special case "--<name>", boolean flag
// Long options come in three varieties:
// "--<name>", config option is a boolean flag
// "--<name>=<value>", formatted as a single argument with the value,
// "--<name> <value>", formatted as two arguments,
const auto npos = std::string::npos;
auto assign_op = i->find('=');
auto name = assign_op == npos ? i->substr(2)
......
......@@ -55,7 +55,6 @@ struct fixture {
void parse(const char* file_content, string_list args = {}) {
cfg.clear();
cfg.remainder.clear();
std::istringstream conf{file_content};
if (auto err = cfg.parse(std::move(args), conf))
CAF_FAIL("parse() failed: " << err);
......@@ -150,6 +149,21 @@ CAF_TEST(file input overrides defaults but CLI args always win) {
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
// content(cfg) are equal to `value`.
#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