utils: config_src::add_command_line_options(): drop name and desc args

Now that there are no ad-hoc aliases needing to overwrite the name and
description parameter of this method, we can drop these and have each
config item just use `name()` and `desc()` to access these.
This commit is contained in:
Botond Dénes
2020-07-27 15:42:49 +03:00
parent dc23736d0c
commit 9faaf46d4b
5 changed files with 12 additions and 22 deletions

View File

@@ -808,24 +808,23 @@ namespace utils {
template<>
void config_file::named_value<db::config::seed_provider_type>::add_command_line_option(
boost::program_options::options_description_easy_init& init,
const std::string_view& name, const std::string_view& desc) {
init((hyphenate(name) + "-class-name").data(),
boost::program_options::options_description_easy_init& init) {
init((hyphenate(name()) + "-class-name").data(),
value_ex<sstring>()->notifier(
[this](sstring new_class_name) {
auto old_seed_provider = operator()();
old_seed_provider.class_name = new_class_name;
set(std::move(old_seed_provider), config_source::CommandLine);
}),
desc.data());
init((hyphenate(name) + "-parameters").data(),
desc().data());
init((hyphenate(name()) + "-parameters").data(),
value_ex<std::unordered_map<sstring, sstring>>()->notifier(
[this](std::unordered_map<sstring, sstring> new_parameters) {
auto old_seed_provider = operator()();
old_seed_provider.parameters = new_parameters;
set(std::move(old_seed_provider), config_source::CommandLine);
}),
desc.data());
desc().data());
}
}

View File

@@ -343,8 +343,7 @@ private:
return this->is_set() ? (*this)() : t;
}
// do not add to boost::options. We only care about yaml config
void add_command_line_option(boost::program_options::options_description_easy_init&,
const std::string_view&, const std::string_view&) override {}
void add_command_line_option(boost::program_options::options_description_easy_init&) override {}
};
log_legacy_value<seastar::log_level> default_log_level;

View File

@@ -270,10 +270,7 @@ bpo::options_description_easy_init&
utils::config_file::add_options(bpo::options_description_easy_init& init) {
for (config_src& src : _cfgs) {
if (src.status() == value_status::Used) {
auto&& name = src.name();
sstring tmp(name.begin(), name.end());
std::replace(tmp.begin(), tmp.end(), '_', '-');
src.add_command_line_option(init, tmp, src.desc());
src.add_command_line_option(init);
}
}
return init;

View File

@@ -135,9 +135,7 @@ public:
return _cf;
}
bool matches(std::string_view name) const;
virtual void add_command_line_option(
bpo::options_description_easy_init&, const std::string_view&,
const std::string_view&) = 0;
virtual void add_command_line_option(bpo::options_description_easy_init&) = 0;
virtual void set_value(const YAML::Node&) = 0;
virtual value_status status() const = 0;
virtual config_source source() const = 0;
@@ -240,8 +238,7 @@ public:
return the_value().observe(std::move(callback));
}
void add_command_line_option(bpo::options_description_easy_init&,
const std::string_view&, const std::string_view&) override;
void add_command_line_option(bpo::options_description_easy_init&) override;
void set_value(const YAML::Node&) override;
};

View File

@@ -192,14 +192,12 @@ sstring hyphenate(const std::string_view&);
}
template<typename T>
void utils::config_file::named_value<T>::add_command_line_option(
boost::program_options::options_description_easy_init& init,
const std::string_view& name, const std::string_view& desc) {
const auto hyphenated_name = hyphenate(name);
void utils::config_file::named_value<T>::add_command_line_option(boost::program_options::options_description_easy_init& init) {
const auto hyphenated_name = hyphenate(name());
// NOTE. We are not adding default values. We could, but must in that case manually (in some way) geenrate the textual
// version, since the available ostream operators for things like pairs and collections don't match what we can deal with parser-wise.
// See removed ostream operators above.
init(hyphenated_name.data(), value_ex<T>()->notifier([this](T new_val) { set(std::move(new_val), config_source::CommandLine); }), desc.data());
init(hyphenated_name.data(), value_ex<T>()->notifier([this](T new_val) { set(std::move(new_val), config_source::CommandLine); }), desc().data());
if (!alias().empty()) {
const auto alias_desc = fmt::format("Alias for {}", hyphenated_name);