1
0
Fork 0

be more graceful when options are added to a yet-unknown section

This commit is contained in:
jsteemann 2018-07-17 12:08:07 +02:00
parent 1a128799f2
commit abf41c9f6f
2 changed files with 17 additions and 16 deletions

View File

@ -398,9 +398,9 @@ void ProgramOptions::addOption(Option const& option) {
auto it = _sections.find(option.section);
if (it == _sections.end()) {
throw std::logic_error(
std::string("no section defined for program option ") +
option.displayName());
// add an anonymous section now...
addSection(option.section, "");
it = _sections.find(option.section);
}
if (!option.shorthand.empty()) {

View File

@ -127,13 +127,25 @@ class ProgramOptions {
// sets a single old option and its replacement name
void addOldOption(std::string const& old, std::string const& replacement) {
_oldOptions[old] = replacement;
_oldOptions[Option::stripPrefix(old)] = replacement;
}
// adds a section to the options
void addSection(Section const& section) {
checkIfSealed();
_sections.emplace(section.name, section);
auto it = _sections.find(section.name);
if (it == _sections.end()) {
// section not present
_sections.emplace(section.name, section);
} else {
// section already present. check if we need to update it
if (!section.description.empty() && (*it).second.description.empty()) {
// copy over description
(*it).second.description = section.description;
}
}
}
// adds a (regular) section to the program options
@ -141,17 +153,6 @@ class ProgramOptions {
addSection(Section(name, description, "", false, false));
}
// adds a hidden section to the program options
void addHiddenSection(std::string const& name,
std::string const& description) {
addSection(Section(name, description, "", true, false));
}
// adds a hidden and obsolete section to the program options
void addObsoleteSection(std::string const& name) {
addSection(Section(name, "", "", true, true));
}
// adds an option to the program options
void addOption(std::string const& name, std::string const& description,
Parameter* parameter) {