From 8807bb5a0b547b453a51c65100012a85ed59dbcc Mon Sep 17 00:00:00 2001 From: TimQu Date: Mon, 20 May 2019 17:02:33 +0200 Subject: [PATCH] Settings: Added facilities to flag options as advanced and only display them with '--help all'. --- src/storm/settings/Option.cpp | 13 +- src/storm/settings/Option.h | 18 +- src/storm/settings/OptionBuilder.h | 19 +- src/storm/settings/SettingsManager.cpp | 212 +++++++++++++----- src/storm/settings/SettingsManager.h | 31 ++- .../settings/modules/GeneralSettings.cpp | 8 +- src/storm/settings/modules/GeneralSettings.h | 2 +- src/storm/settings/modules/ModuleSettings.cpp | 6 +- src/storm/settings/modules/ModuleSettings.h | 3 +- src/storm/utility/string.cpp | 4 +- 10 files changed, 224 insertions(+), 92 deletions(-) diff --git a/src/storm/settings/Option.cpp b/src/storm/settings/Option.cpp index 338289fe6..1ab2aa23a 100644 --- a/src/storm/settings/Option.cpp +++ b/src/storm/settings/Option.cpp @@ -14,11 +14,11 @@ namespace storm { namespace settings { - Option::Option(std::string const& moduleName, std::string const& longOptionName, std::string const& optionDescription, bool isOptionRequired, bool requireModulePrefix, std::vector> const& optionArguments) : Option(moduleName, longOptionName, "", false, optionDescription, isOptionRequired, requireModulePrefix, optionArguments) { + Option::Option(std::string const& moduleName, std::string const& longOptionName, std::string const& optionDescription, bool isOptionRequired, bool requireModulePrefix, bool isAdvanced, std::vector> const& optionArguments) : Option(moduleName, longOptionName, "", false, optionDescription, isOptionRequired, requireModulePrefix, isAdvanced, optionArguments) { // Intentionally left empty. } - Option::Option(std::string const& moduleName, std::string const& longOptionName, std::string const& shortOptionName, std::string const& optionDescription, bool isOptionRequired, bool requireModulePrefix, std::vector> const& optionArguments) : Option(moduleName, longOptionName, shortOptionName, true, optionDescription, isOptionRequired, requireModulePrefix, optionArguments) { + Option::Option(std::string const& moduleName, std::string const& longOptionName, std::string const& shortOptionName, std::string const& optionDescription, bool isOptionRequired, bool requireModulePrefix, bool isAdvanced, std::vector> const& optionArguments) : Option(moduleName, longOptionName, shortOptionName, true, optionDescription, isOptionRequired, requireModulePrefix, isAdvanced, optionArguments) { // Intentionally left empty. } @@ -85,13 +85,11 @@ namespace storm { std::string const& Option::getLongName() const { return this->longName; } - bool Option::getHasShortName() const { return this->hasShortName; } - std::string const& Option::getShortName() const { return this->shortName; } @@ -108,16 +106,19 @@ namespace storm { return this->isRequired; } - bool Option::getRequiresModulePrefix() const { return this->requireModulePrefix; } + bool Option::getIsAdvanced() const { + return this->isAdvanced; + } + bool Option::getHasOptionBeenSet() const { return this->hasBeenSet; } - Option::Option(std::string const& moduleName, std::string const& longOptionName, std::string const& shortOptionName, bool hasShortOptionName, std::string const& optionDescription, bool isOptionRequired, bool requireModulePrefix, std::vector> const& optionArguments) : longName(longOptionName), hasShortName(hasShortOptionName), shortName(shortOptionName), description(optionDescription), moduleName(moduleName), isRequired(isOptionRequired), requireModulePrefix(requireModulePrefix), hasBeenSet(false), arguments(optionArguments), argumentNameMap() { + Option::Option(std::string const& moduleName, std::string const& longOptionName, std::string const& shortOptionName, bool hasShortOptionName, std::string const& optionDescription, bool isOptionRequired, bool requireModulePrefix, bool isAdvanced, std::vector> const& optionArguments) : longName(longOptionName), hasShortName(hasShortOptionName), shortName(shortOptionName), description(optionDescription), moduleName(moduleName), isRequired(isOptionRequired), requireModulePrefix(requireModulePrefix), isAdvanced(isAdvanced), hasBeenSet(false), arguments(optionArguments), argumentNameMap() { // First, do some sanity checks. STORM_LOG_THROW(!longName.empty(), storm::exceptions::IllegalArgumentException, "Unable to construct option with empty name."); STORM_LOG_THROW(!moduleName.empty(), storm::exceptions::IllegalArgumentException, "Unable to construct option with empty module name."); diff --git a/src/storm/settings/Option.h b/src/storm/settings/Option.h index 1adf8ddff..0ff675d21 100644 --- a/src/storm/settings/Option.h +++ b/src/storm/settings/Option.h @@ -40,9 +40,10 @@ namespace storm { * @param isOptionRequired Sets whether the option is required to appear. * @param requireModulePrefix A flag that indicates whether this option requires to be prefixed with the * module name. + * @param isAdvanced A flag that indicates whether this option is only displayed in the advanced help * @param optionArguments The arguments of the option. */ - Option(std::string const& moduleName, std::string const& longOptionName, std::string const& optionDescription, bool isOptionRequired, bool requireModulePrefix, std::vector> const& optionArguments = std::vector>()); + Option(std::string const& moduleName, std::string const& longOptionName, std::string const& optionDescription, bool isOptionRequired, bool requireModulePrefix, bool isAdvanced, std::vector> const& optionArguments = std::vector>()); /*! * Creates an option with the given parameters. @@ -53,10 +54,10 @@ namespace storm { * @param optionDescription The description of the option. * @param isOptionRequired Sets whether the option is required to appear. * @param requireModulePrefix A flag that indicates whether this option requires to be prefixed with the - * module name. + * @param isAdvanced A flag that indicates whether this option is only displayed in the advanced help * @param optionArguments The arguments of the option. */ - Option(std::string const& moduleName, std::string const& longOptionName, std::string const& shortOptionName, std::string const& optionDescription, bool isOptionRequired, bool requireModulePrefix, std::vector> const& optionArguments = std::vector>()); + Option(std::string const& moduleName, std::string const& longOptionName, std::string const& shortOptionName, std::string const& optionDescription, bool isOptionRequired, bool requireModulePrefix, bool isAdvanced, std::vector> const& optionArguments = std::vector>()); /*! * Checks whether the given option is compatible with the current one. If not, an exception is thrown. @@ -161,6 +162,11 @@ namespace storm { */ bool getHasOptionBeenSet() const; + /*! + * Retrieves whether the option is only displayed in the advanced help. + */ + bool getIsAdvanced() const; + /*! * Retrieves the arguments of the option. * @@ -199,6 +205,9 @@ namespace storm { // A flag that indicates whether this option is required to be prefixed with the module name. bool requireModulePrefix; + // A flag that indicates whether this option is only displayed in the advanced help. + bool isAdvanced; + // A flag that indicates whether this option has been set. bool hasBeenSet; @@ -219,9 +228,10 @@ namespace storm { * @param isOptionRequired Sets whether the option is required to appear. * @param requireModulePrefix A flag that indicates whether this option requires to be prefixed with the * module name. + * @param isAdvanced A flag that indicates whether this option is only displayed in the advanced help * @param optionArguments The arguments of the option. */ - Option(std::string const& moduleName, std::string const& longOptionName, std::string const& shortOptionName, bool hasShortOptionName, std::string const& optionDescription, bool isOptionRequired, bool requireModulePrefix, std::vector> const& optionArguments = std::vector>()); + Option(std::string const& moduleName, std::string const& longOptionName, std::string const& shortOptionName, bool hasShortOptionName, std::string const& optionDescription, bool isOptionRequired, bool requireModulePrefix, bool isAdvanced, std::vector> const& optionArguments = std::vector>()); /*! * Sets the flag that marks the option as being (un)set. diff --git a/src/storm/settings/OptionBuilder.h b/src/storm/settings/OptionBuilder.h index f6b2bfea1..643b13b3b 100644 --- a/src/storm/settings/OptionBuilder.h +++ b/src/storm/settings/OptionBuilder.h @@ -33,7 +33,7 @@ namespace storm { * @param requireModulePrefix Sets whether this option can only be set by specifying the module name as its prefix. * @param description A description that explains the purpose of this option. */ - OptionBuilder(std::string const& moduleName, std::string const& longName, bool requireModulePrefix, std::string const& description) : longName(longName), shortName(""), hasShortName(false), description(description), moduleName(moduleName), requireModulePrefix(requireModulePrefix), isRequired(false), isBuild(false), arguments(), argumentNameSet() { + OptionBuilder(std::string const& moduleName, std::string const& longName, bool requireModulePrefix, std::string const& description) : longName(longName), shortName(""), hasShortName(false), description(description), moduleName(moduleName), requireModulePrefix(requireModulePrefix), isRequired(false), isAdvanced(false), isBuild(false), arguments(), argumentNameSet() { // Intentionally left empty. } @@ -60,6 +60,14 @@ namespace storm { return *this; } + /*! + * Sets whether the option is only displayed in the advanced help. + */ + OptionBuilder& setIsAdvanced(bool isAdvanced = true) { + this->isAdvanced = isAdvanced; + return *this; + } + /*! * Adds the given argument to the arguments of this option. * @@ -89,9 +97,9 @@ namespace storm { this->isBuild = true; if (this->hasShortName) { - return std::shared_ptr