Print invalid and unknown options on startup

This commit is contained in:
Robbert van der Helm
2020-10-13 14:20:51 +02:00
parent a125f7a535
commit a1162c2256
6 changed files with 87 additions and 15 deletions
+25 -6
View File
@@ -75,12 +75,31 @@ Configuration::Configuration(const fs::path& config_path,
matched_pattern = pattern;
// If the table is missing some fields then they will simply be left at
// their defaults
editor_double_embed =
table["editor_double_embed"].value<bool>().value_or(false);
hack_reaper_update_display =
table["hack_reaper_update_display"].value<bool>().value_or(false);
group = table["group"].value<std::string>();
// their defaults. At this point I'd really wish C++ could do pattern
// matching.
for (const auto& [key, value] : table) {
if (key == "editor_double_embed") {
if (const auto parsed_value = value.as_boolean()) {
editor_double_embed = parsed_value->get();
} else {
invalid_options.push_back(key);
}
} else if (key == "hack_reaper_update_display") {
if (const auto parsed_value = value.as_boolean()) {
hack_reaper_update_display = parsed_value->get();
} else {
invalid_options.push_back(key);
}
} else if (key == "group") {
if (const auto parsed_value = value.as_string()) {
group = parsed_value->get();
} else {
invalid_options.push_back(key);
}
} else {
unknown_options.push_back(key);
}
}
break;
}
+18
View File
@@ -112,6 +112,19 @@ class Configuration {
*/
std::optional<std::string> matched_pattern;
/**
* Options with a wrong argument type. These will be printed separately from
* `unknown_options` to avoid confusion.
*/
std::vector<std::string> invalid_options;
/**
* Unrecognized configuration options, likely caused by an old option that
* served as a hack or a workaround getting removed. Will be printed on
* startup when not empty.
*/
std::vector<std::string> unknown_options;
template <typename S>
void serialize(S& s) {
s.value1b(editor_double_embed);
@@ -122,5 +135,10 @@ class Configuration {
[](S& s, auto& v) { s.ext(v, bitsery::ext::BoostPath()); });
s.ext(matched_pattern, bitsery::ext::StdOptional(),
[](S& s, auto& v) { s.text1b(v, 4096); });
s.container(invalid_options, 1024,
[](S& s, auto& v) { s.text1b(v, 4096); });
s.container(unknown_options, 1024,
[](S& s, auto& v) { s.text1b(v, 4096); });
}
};