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
+3
View File
@@ -25,6 +25,9 @@ Versioning](https://semver.org/spec/v2.0.0.html).
to type text with spaces inside of a plugin editor window. Please let me know
if this causes any issues and we'll try to come up with a middle ground.
- Both unrecognized and invalid options will now be printed on started to make
debugging easier.
- Added a note to the message saying that libSwell GUI support has been disabled
that his is perfectly normal when using REAPER. The message now also contains
the suggestion to enable the `hack_reaper_update_display` workaround for
+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); });
}
};
+22 -9
View File
@@ -684,20 +684,33 @@ void PluginBridge::log_init_message() {
}
init_msg << "'" << std::endl;
bool other_options_set = false;
init_msg << "other options: '";
init_msg << "other options: ";
std::vector<std::string> other_options;
if (config.editor_double_embed) {
init_msg << "editor: double embed";
other_options_set = true;
other_options.push_back("editor: double embed");
}
if (config.hack_reaper_update_display) {
init_msg << "hack: REAPER 'audioMasterUpdateDisplay' workaround";
other_options_set = true;
other_options.push_back(
"hack: REAPER audioMasterUpdateDisplay() workaround");
}
if (!other_options_set) {
init_msg << "<none>";
if (!other_options.empty()) {
init_msg << join_quoted_strings(other_options) << std::endl;
} else {
init_msg << "'<none>'" << std::endl;
}
// To make debugging easier, we'll print both unrecognized options (that
// might be left over when an option gets removed) as well as options have
// the wrong argument types
if (!config.invalid_options.empty()) {
init_msg << "invalid arguments: "
<< join_quoted_strings(config.invalid_options)
<< " (check the readme for more information)" << std::endl;
}
if (!config.unknown_options.empty()) {
init_msg << "unrecognized options: "
<< join_quoted_strings(config.unknown_options) << std::endl;
}
init_msg << "'" << std::endl;
init_msg << std::endl;
// Include a list of enabled compile-tiem features, mostly to make debug
+11
View File
@@ -269,6 +269,17 @@ std::string get_wine_version() {
return version_string;
}
std::string join_quoted_strings(std::vector<std::string>& strings) {
bool is_first = true;
std::ostringstream joined_strigns{};
for (const auto& option : strings) {
joined_strigns << (is_first ? "'" : ", '") << option << "'";
is_first = false;
}
return joined_strigns.str();
}
Configuration load_config_for(const fs::path& yabridge_path) {
// First find the closest `yabridge.tmol` file for the plugin, falling back
// to default configuration settings if it doesn't exist
+8
View File
@@ -166,6 +166,14 @@ boost::filesystem::path get_this_file_location();
*/
std::string get_wine_version();
/**
* Join a vector of strings with commas while wrapping the strings in quotes.
* For example, `join_quoted_strings(std::vector<string>{"string", "another
* string", "also a string"})` outputs `"'string', 'another string', 'also a
* string'"`. This is used to format the initialisation message.
*/
std::string join_quoted_strings(std::vector<std::string>& strings);
/**
* Load the configuration that belongs to a copy of or symlink to
* `libyabridge.so`. If no configuration file could be found then this will