Skip to content

Commit

Permalink
imageconverter,sceneconverter: support option subgroups as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Apr 22, 2020
1 parent cdac496 commit 17c3e9b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
20 changes: 17 additions & 3 deletions src/Magnum/Trade/Implementation/converterUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,34 @@ void setOptions(PluginManager::AbstractPlugin& plugin, const std::string& option
Utility::String::trimInPlace(keyValue[0]);
Utility::String::trimInPlace(keyValue[2]);

std::vector<std::string> keyParts = Utility::String::split(keyValue[0], '/');
CORRADE_INTERNAL_ASSERT(!keyParts.empty());
Utility::ConfigurationGroup* group = &plugin.configuration();
bool groupNotRecognized = false;
for(std::size_t i = 0; i != keyParts.size() - 1; ++i) {
Utility::ConfigurationGroup* subgroup = group->group(keyParts[i]);
if(!subgroup) {
groupNotRecognized = true;
subgroup = group->addGroup(keyParts[i]);
}
group = subgroup;
}

/* Provide a warning message in case the plugin doesn't define given
option in its default config. The plugin is not *required* to have
those tho (could be backward compatibility entries, for example), so
not an error. */
if(!plugin.configuration().valueCount(keyValue[0]))
if(groupNotRecognized || !group->hasValue(keyParts.back())) {
Warning{} << "Option" << keyValue[0] << "not recognized by" << plugin.plugin();
}

/* If the option doesn't have an =, treat it as a boolean flag that's
set to true. While there's no similar way to do an inverse, it's
still nicer than causing a fatal error with those. */
if(keyValue[1].empty())
plugin.configuration().setValue(keyValue[0], true);
group->setValue(keyParts.back(), true);
else
plugin.configuration().setValue(keyValue[0], keyValue[2]);
group->setValue(keyParts.back(), keyValue[2]);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/Magnum/Trade/imageconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ need to be specified.
The `-i` / `--importer-options` and `-c` / `--converter-options` arguments
accept a comma-separated list of key/value pairs to set in the importer /
converter plugin configuration. If the `=` character is omitted, it's
equivalent to saying `key=true`.
equivalent to saying `key=true`; configuration subgroups are delimited with
`/`.
@section magnum-imageconverter-example Example usage
Expand Down Expand Up @@ -165,7 +166,7 @@ be specified.
The -i / --importer-options and -c / --converter-options arguments accept a
comma-separated list of key/value pairs to set in the importer / converter
plugin configuration. If the = character is omitted, it's equivalent to saying
key=true.)")
key=true; configuration subgroups are delimited with /.)")
.parse(argc, argv);

PluginManager::Manager<Trade::AbstractImporter> importerManager{
Expand Down
5 changes: 3 additions & 2 deletions src/Magnum/Trade/sceneconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ and images present in the file. **This option is currently mandatory.**
The `-i` / `--importer-options` and `-c` / `--converter-options` arguments
accept a comma-separated list of key/value pairs to set in the importer /
converter plugin configuration. If the `=` character is omitted, it's
equivalent to saying `key=true`.
equivalent to saying `key=true`; configuration subgroups are delimited with
`/`.
@see @ref magnum-imageconverter
*/
Expand Down Expand Up @@ -162,7 +163,7 @@ images present in the file.
The -i / --importer-options and -c / --converter-options arguments accept a
comma-separated list of key/value pairs to set in the importer / converter
plugin configuration. If the = character is omitted, it's equivalent to saying
key=true.)")
key=true; configuration subgroups are delimited with /.)")
.parse(argc, argv);

/* Load importer plugin, or use the blob shim in case the extension
Expand Down

0 comments on commit 17c3e9b

Please sign in to comment.