From 7e56e0d8f747ea52760b52ec06455119d12ce017 Mon Sep 17 00:00:00 2001 From: dehnert Date: Tue, 23 Sep 2014 22:46:13 +0200 Subject: [PATCH] Added feature to also show help for a given option name. Former-commit-id: 4a2a37a87408bf34cc63f204b31d1d77c7709e1c --- src/settings/SettingsManager.cpp | 32 ++++++++++++++++--- src/settings/SettingsManager.h | 10 +++--- src/settings/modules/GeneralSettings.cpp | 5 ++- .../modules/GmmxxEquationSolverSettings.cpp | 6 ++-- .../modules/NativeEquationSolverSettings.cpp | 6 ++-- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/settings/SettingsManager.cpp b/src/settings/SettingsManager.cpp index db06bf63d..812578832 100644 --- a/src/settings/SettingsManager.cpp +++ b/src/settings/SettingsManager.cpp @@ -111,18 +111,42 @@ namespace storm { LOG_ASSERT(false, "Not yet implemented"); } - void SettingsManager::printHelp(std::string const& moduleName) const { + void SettingsManager::printHelp(std::string const& hint) const { std::cout << "usage: storm [options]" << std::endl << std::endl; - if (moduleName == "all") { + if (hint == "all") { // Find longest option name. uint_fast64_t maxLength = getPrintLengthOfLongestOption(); for (auto const& moduleName : this->moduleNames) { printHelpForModule(moduleName, maxLength); } } else { - uint_fast64_t maxLength = getPrintLengthOfLongestOption(moduleName); - printHelpForModule(moduleName, maxLength); + auto moduleIterator = this->modules.find(hint); + + // If the supplied information is a module, print the help text of the module. + if (moduleIterator != this->modules.end()) { + uint_fast64_t maxLength = getPrintLengthOfLongestOption(hint); + printHelpForModule(hint, maxLength); + } else { + auto optionIterator = this->longNameToOptions.find(hint); + + if (optionIterator != this->longNameToOptions.end()) { + // Save the flags for std::cout so we can manipulate them and be sure they will be restored as soon as this + // stream goes out of scope. + boost::io::ios_flags_saver out(std::cout); + + std::cout << "Matching options:" << std::endl; + uint_fast64_t maxLength = 0; + for (auto const& option : optionIterator->second) { + maxLength = std::max(maxLength, option->getPrintLength()); + } + for (auto const& option : optionIterator->second) { + std::cout << std::setw(maxLength) << std::left << *option << std::endl; + } + } else { + LOG_THROW(false, storm::exceptions::IllegalArgumentValueException, "Unable to show help for unknown entity '" << hint << "'."); + } + } } } diff --git a/src/settings/SettingsManager.h b/src/settings/SettingsManager.h index 091695323..0b27c76fd 100644 --- a/src/settings/SettingsManager.h +++ b/src/settings/SettingsManager.h @@ -74,14 +74,12 @@ namespace storm { void setFromConfigurationFile(std::string const& configFilename); /*! - * This function prints a help message to the standard output. Optionally, a module name can be given. If - * it is present, name must correspond to a known module. Then, only the help text for this module is - * printed. + * This function prints a help message to the standard output. Optionally, a string can be given that either + * identifies a module or some options to cut down the help text. * - * @param moduleName The name of the module for which to show the help or "all" if the full help text is to - * be printed. + * @param hint The name of a module, some options or "all" for the full help text. */ - void printHelp(std::string const& moduleName = "all") const; + void printHelp(std::string const& hint = "all") const; /*! * This function prints a help message for the specified module to the standard output. diff --git a/src/settings/modules/GeneralSettings.cpp b/src/settings/modules/GeneralSettings.cpp index fa3cea129..3d431b3df 100644 --- a/src/settings/modules/GeneralSettings.cpp +++ b/src/settings/modules/GeneralSettings.cpp @@ -37,11 +37,10 @@ namespace storm { const std::string GeneralSettings::constantsOptionShortName = "const"; GeneralSettings::GeneralSettings(storm::settings::SettingsManager& settingsManager) : ModuleSettings(settingsManager, moduleName) { - std::vector moduleNames = {"all", "general", "debug", "cudd", "counterexample", "glpk", "gurobi", "gmm++", "native"}; this->addOption(storm::settings::OptionBuilder(moduleName, helpOptionName, false, "Shows all available options, arguments and descriptions.").setShortName(helpOptionShortName) - .addArgument(storm::settings::ArgumentBuilder::createStringArgument("module", "The module for which to show the help or 'all' for all modules.").setDefaultValueString("all").addValidationFunctionString(storm::settings::ArgumentValidators::stringInListValidator(moduleNames)).build()).build()); + .addArgument(storm::settings::ArgumentBuilder::createStringArgument("module", "The module for which to show the help or 'all' for all modules.").setDefaultValueString("all").build()).build()); this->addOption(storm::settings::OptionBuilder(moduleName, verboseOptionName, false, "Enables more verbose output.").setShortName(verboseOptionShortName).build()); - this->addOption(storm::settings::OptionBuilder(moduleName, precisionOptionName, true, "The internally used precision.").setShortName(precisionOptionShortName) + this->addOption(storm::settings::OptionBuilder(moduleName, precisionOptionName, false, "The internally used precision.").setShortName(precisionOptionShortName) .addArgument(storm::settings::ArgumentBuilder::createDoubleArgument("value", "The precision to use.").setDefaultValueDouble(1e-06).addValidationFunctionDouble(storm::settings::ArgumentValidators::doubleRangeValidatorExcluding(0.0, 1.0)).build()).build()); this->addOption(storm::settings::OptionBuilder(moduleName, exportDotOptionName, "", "If given, the loaded model will be written to the specified file in the dot format.") .addArgument(storm::settings::ArgumentBuilder::createStringArgument("filename", "The name of the file to which the model is to be written.").build()).build()); diff --git a/src/settings/modules/GmmxxEquationSolverSettings.cpp b/src/settings/modules/GmmxxEquationSolverSettings.cpp index 9843461e2..434fc275f 100644 --- a/src/settings/modules/GmmxxEquationSolverSettings.cpp +++ b/src/settings/modules/GmmxxEquationSolverSettings.cpp @@ -25,11 +25,11 @@ namespace storm { this->addOption(storm::settings::OptionBuilder(moduleName, restartOptionName, true, "The number of iteration until restarted methods are actually restarted.").addArgument(storm::settings::ArgumentBuilder::createUnsignedIntegerArgument("count", "The number of iterations.").setDefaultValueUnsignedInteger(50).build()).build()); - this->addOption(storm::settings::OptionBuilder(moduleName, maximalIterationsOptionName, true, "The maximal number of iterations to perform before iterative solving is aborted.").setShortName(maximalIterationsOptionShortName).addArgument(storm::settings::ArgumentBuilder::createUnsignedIntegerArgument("count", "The maximal iteration count.").setDefaultValueUnsignedInteger(20000).build()).build()); + this->addOption(storm::settings::OptionBuilder(moduleName, maximalIterationsOptionName, false, "The maximal number of iterations to perform before iterative solving is aborted.").setShortName(maximalIterationsOptionShortName).addArgument(storm::settings::ArgumentBuilder::createUnsignedIntegerArgument("count", "The maximal iteration count.").setDefaultValueUnsignedInteger(20000).build()).build()); - this->addOption(storm::settings::OptionBuilder(moduleName, precisionOptionName, true, "The precision used for detecting convergence of iterative methods.").addArgument(storm::settings::ArgumentBuilder::createDoubleArgument("value", "The precision to achieve.").setDefaultValueDouble(1e-06).addValidationFunctionDouble(storm::settings::ArgumentValidators::doubleRangeValidatorExcluding(0.0, 1.0)).build()).build()); + this->addOption(storm::settings::OptionBuilder(moduleName, precisionOptionName, false, "The precision used for detecting convergence of iterative methods.").addArgument(storm::settings::ArgumentBuilder::createDoubleArgument("value", "The precision to achieve.").setDefaultValueDouble(1e-06).addValidationFunctionDouble(storm::settings::ArgumentValidators::doubleRangeValidatorExcluding(0.0, 1.0)).build()).build()); - this->addOption(storm::settings::OptionBuilder(moduleName, absoluteOptionName, true, "Sets whether the relative or the absolute error is considered for detecting convergence.").build()); + this->addOption(storm::settings::OptionBuilder(moduleName, absoluteOptionName, false, "Sets whether the relative or the absolute error is considered for detecting convergence.").build()); } GmmxxEquationSolverSettings::LinearEquationTechnique GmmxxEquationSolverSettings::getLinearEquationSystemTechnique() const { diff --git a/src/settings/modules/NativeEquationSolverSettings.cpp b/src/settings/modules/NativeEquationSolverSettings.cpp index a96b424bb..cdde61942 100644 --- a/src/settings/modules/NativeEquationSolverSettings.cpp +++ b/src/settings/modules/NativeEquationSolverSettings.cpp @@ -17,11 +17,11 @@ namespace storm { std::vector methods = { "jacobi" }; this->addOption(storm::settings::OptionBuilder(moduleName, techniqueOptionName, true, "The method to be used for solving linear equation systems with the native engine. Available are: { jacobi }.").addArgument(storm::settings::ArgumentBuilder::createStringArgument("name", "The name of the method to use.").addValidationFunctionString(storm::settings::ArgumentValidators::stringInListValidator(methods)).setDefaultValueString("jacobi").build()).build()); - this->addOption(storm::settings::OptionBuilder(moduleName, maximalIterationsOptionName, true, "The maximal number of iterations to perform before iterative solving is aborted.").setShortName(maximalIterationsOptionShortName).addArgument(storm::settings::ArgumentBuilder::createUnsignedIntegerArgument("count", "The maximal iteration count.").setDefaultValueUnsignedInteger(20000).build()).build()); + this->addOption(storm::settings::OptionBuilder(moduleName, maximalIterationsOptionName, false, "The maximal number of iterations to perform before iterative solving is aborted.").setShortName(maximalIterationsOptionShortName).addArgument(storm::settings::ArgumentBuilder::createUnsignedIntegerArgument("count", "The maximal iteration count.").setDefaultValueUnsignedInteger(20000).build()).build()); - this->addOption(storm::settings::OptionBuilder(moduleName, precisionOptionName, true, "The precision used for detecting convergence of iterative methods.").addArgument(storm::settings::ArgumentBuilder::createDoubleArgument("value", "The precision to achieve.").setDefaultValueDouble(1e-06).addValidationFunctionDouble(storm::settings::ArgumentValidators::doubleRangeValidatorExcluding(0.0, 1.0)).build()).build()); + this->addOption(storm::settings::OptionBuilder(moduleName, precisionOptionName, false, "The precision used for detecting convergence of iterative methods.").addArgument(storm::settings::ArgumentBuilder::createDoubleArgument("value", "The precision to achieve.").setDefaultValueDouble(1e-06).addValidationFunctionDouble(storm::settings::ArgumentValidators::doubleRangeValidatorExcluding(0.0, 1.0)).build()).build()); - this->addOption(storm::settings::OptionBuilder(moduleName, absoluteOptionName, true, "Sets whether the relative or the absolute error is considered for detecting convergence.").build()); + this->addOption(storm::settings::OptionBuilder(moduleName, absoluteOptionName, false, "Sets whether the relative or the absolute error is considered for detecting convergence.").build()); } NativeEquationSolverSettings::LinearEquationTechnique NativeEquationSolverSettings::getLinearEquationSystemTechnique() const {