* Does not throw.
*/
explicit RootHelpTopic(const std::string &binaryName)
- : binaryName_(binaryName), commonOptions_(NULL)
+ : binaryName_(binaryName)
{
}
- //! Sets the common options for the wrapper binary.
- void setCommonOptions(const Options *options)
- {
- commonOptions_ = options;
- }
-
virtual void writeHelp(const HelpWriterContext &context) const;
private:
std::string binaryName_;
- const Options *commonOptions_;
GMX_DISALLOW_COPY_AND_ASSIGN(RootHelpTopic);
};
"Root help is not implemented for this output format"));
}
{
- CommandLineHelpContext cmdlineContext(context);
+ CommandLineCommonOptionsHolder optionsHolder;
+ CommandLineHelpContext cmdlineContext(context);
+ optionsHolder.initOptions();
cmdlineContext.setModuleDisplayName(binaryName_);
// TODO: Add <command> [<args>] into the synopsis.
// TODO: Propagate the -hidden option here.
- CommandLineHelpWriter(*commonOptions_)
+ CommandLineHelpWriter(*optionsHolder.options())
.writeHelp(cmdlineContext);
}
// TODO: Consider printing a list of "core" commands. Would require someone
impl_->bHidden_ = bHidden;
}
-void CommandLineHelpModule::setCommonOptions(const Options *options)
-{
- impl_->rootTopic_->setCommonOptions(options);
-}
-
void CommandLineHelpModule::setModuleOverride(
const CommandLineModuleInterface &module)
{
#include "cmdlinemodule.h"
#include "cmdlinemodulemanager.h"
+#include "gromacs/legacyheaders/copyrite.h"
+#include "gromacs/options/options.h"
#include "gromacs/utility/common.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/uniqueptr.h"
namespace gmx
{
+
+//! \addtogroup module_commandline
+//! \{
+
//! Container type for mapping module names to module objects.
typedef std::map<std::string, CommandLineModulePointer> CommandLineModuleMap;
* This class contains the state of a module group. CommandLineModuleGroup
* provides the public interface to construct/alter the state, and
* CommandLineModuleManager and its associated classes use it for help output.
- *
- * \ingroup module_commandline
*/
class CommandLineModuleGroupData
{
typedef std::vector<CommandLineModuleGroupDataPointer>
CommandLineModuleGroupList;
+/*! \internal
+ * \brief
+ * Encapsulates some handling of common options to the wrapper binary.
+ */
+class CommandLineCommonOptionsHolder
+{
+ public:
+ CommandLineCommonOptionsHolder();
+ ~CommandLineCommonOptionsHolder();
+
+ //! Initializes the common options.
+ void initOptions();
+ /*! \brief
+ * Finishes option parsing.
+ *
+ * \returns `false` if the wrapper binary should quit without executing
+ * any module.
+ */
+ bool finishOptions();
+
+ //! Returns the internal Options object.
+ Options *options() { return &options_; }
+ //! Returns the settings for printing startup information.
+ const BinaryInformationSettings &binaryInfoSettings() const
+ {
+ return binaryInfoSettings_;
+ }
+
+ /*! \brief
+ * Returns `true` if common options are set such that the wrapper
+ * binary should quit, without running the actual module.
+ */
+ bool shouldIgnoreActualModule() const
+ {
+ return bHelp_ || bVersion_;
+ }
+ //! Returns whether common options specify showing help.
+ bool shouldShowHelp() const { return bHelp_; }
+ //! Returns whether common options specify showing hidden options in help.
+ bool shouldShowHidden() const { return bHidden_; }
+ //! Returns whether common options specify quiet execution.
+ bool shouldBeQuiet() const
+ {
+ return bQuiet_ && !bVersion_;
+ }
+
+ //! Returns the file to which startup information should be printed.
+ FILE *startupInfoFile() const { return (bVersion_ ? stdout : stderr); }
+
+ private:
+ Options options_;
+ //! Settings for what to write in the startup header.
+ BinaryInformationSettings binaryInfoSettings_;
+ bool bHelp_;
+ bool bHidden_;
+ bool bQuiet_;
+ bool bVersion_;
+ bool bCopyright_;
+
+ GMX_DISALLOW_COPY_AND_ASSIGN(CommandLineCommonOptionsHolder);
+};
+
+//! \}
+
} // namespace gmx
#endif
};
+//! \}
+
+} // namespace
+
/********************************************************************
- * CommonOptionsHolder
+ * CommandLineCommonOptionsHolder
*/
-/*! \brief
- * Encapsulates some handling of common options to the wrapper binary.
- */
-class CommonOptionsHolder
+CommandLineCommonOptionsHolder::CommandLineCommonOptionsHolder()
+ : options_(NULL, NULL), bHelp_(false), bHidden_(false),
+ bQuiet_(false), bVersion_(false), bCopyright_(true)
{
- public:
- CommonOptionsHolder()
- : options_(NULL, NULL), bHelp_(false), bHidden_(false),
- bQuiet_(false), bVersion_(false), bCopyright_(true)
- {
- binaryInfoSettings_.copyright(true);
- }
-
- //! Initializes the common options.
- void initOptions()
- {
- options_.addOption(BooleanOption("h").store(&bHelp_)
- .description("Print help and quit"));
- options_.addOption(BooleanOption("hidden").store(&bHidden_)
- .hidden()
- .description("Show hidden options in help"));
- options_.addOption(BooleanOption("quiet").store(&bQuiet_)
- .description("Do not print common startup info or quotes"));
- options_.addOption(BooleanOption("version").store(&bVersion_)
- .description("Print extended version information and quit"));
- options_.addOption(BooleanOption("copyright").store(&bCopyright_)
- .description("Print copyright information on startup"));
- }
-
- /*! \brief
- * Finishes option parsing.
- *
- * \returns `false` if the wrapper binary should quit without executing
- * any module.
- */
- bool finishOptions()
- {
- options_.finish();
- binaryInfoSettings_.extendedInfo(bVersion_);
- // The latter condition suppresses the copyright with
- // -quiet -version.
- binaryInfoSettings_.copyright(bCopyright_ && !bQuiet_);
- return !bVersion_;
- }
-
- //! Returns the internal Options object.
- Options *options() { return &options_; }
- //! Returns the settings for printing startup information.
- const BinaryInformationSettings &binaryInfoSettings() const
- {
- return binaryInfoSettings_;
- }
-
- /*! \brief
- * Returns `true` if common options are set such that the wrapper
- * binary should quit, without running the actual module.
- */
- bool shouldIgnoreActualModule() const
- {
- return bHelp_ || bVersion_;
- }
- //! Returns whether common options specify showing help.
- bool shouldShowHelp() const { return bHelp_; }
- //! Returns whether common options specify showing hidden options in help.
- bool shouldShowHidden() const { return bHidden_; }
- //! Returns whether common options specify quiet execution.
- bool shouldBeQuiet() const
- {
- return bQuiet_ && !bVersion_;
- }
-
- //! Returns the file to which startup information should be printed.
- FILE *startupInfoFile() const { return (bVersion_ ? stdout : stderr); }
+ binaryInfoSettings_.copyright(true);
+}
- private:
- Options options_;
- //! Settings for what to write in the startup header.
- BinaryInformationSettings binaryInfoSettings_;
- bool bHelp_;
- bool bHidden_;
- bool bQuiet_;
- bool bVersion_;
- bool bCopyright_;
-};
+CommandLineCommonOptionsHolder::~CommandLineCommonOptionsHolder()
+{
+}
-//! \}
+void CommandLineCommonOptionsHolder::initOptions()
+{
+ options_.addOption(BooleanOption("h").store(&bHelp_)
+ .description("Print help and quit"));
+ options_.addOption(BooleanOption("hidden").store(&bHidden_)
+ .hidden()
+ .description("Show hidden options in help"));
+ options_.addOption(BooleanOption("quiet").store(&bQuiet_)
+ .description("Do not print common startup info or quotes"));
+ options_.addOption(BooleanOption("version").store(&bVersion_)
+ .description("Print extended version information and quit"));
+ options_.addOption(BooleanOption("copyright").store(&bCopyright_)
+ .description("Print copyright information on startup"));
+}
-} // namespace
+bool CommandLineCommonOptionsHolder::finishOptions()
+{
+ options_.finish();
+ binaryInfoSettings_.extendedInfo(bVersion_);
+ // The latter condition suppresses the copyright with
+ // -quiet -version.
+ binaryInfoSettings_.copyright(bCopyright_ && !bQuiet_);
+ return !bVersion_;
+}
/********************************************************************
* CommandLineModuleManager::Impl
* arguments that should be passed to it.
*/
CommandLineModuleInterface *
- processCommonOptions(CommonOptionsHolder *optionsHolder,
+ processCommonOptions(CommandLineCommonOptionsHolder *optionsHolder,
int *argc, char ***argv);
/*! \brief
CommandLineModuleInterface *
CommandLineModuleManager::Impl::processCommonOptions(
- CommonOptionsHolder *optionsHolder, int *argc, char ***argv)
+ CommandLineCommonOptionsHolder *optionsHolder, int *argc, char ***argv)
{
// Check if we are directly invoking a certain module.
CommandLineModuleInterface *module = singleModule_;
if (module == helpModule_)
{
helpModule_->setShowHidden(optionsHolder->shouldShowHidden());
- helpModule_->setCommonOptions(optionsHolder->options());
}
return module;
}
int CommandLineModuleManager::run(int argc, char *argv[])
{
- CommandLineModuleInterface *module;
- const bool bMaster = (!gmx_mpi_initialized() || gmx_node_rank() == 0);
- bool bQuiet = impl_->bQuiet_ || !bMaster;
- CommonOptionsHolder optionsHolder;
+ CommandLineModuleInterface *module;
+ const bool bMaster = (!gmx_mpi_initialized() || gmx_node_rank() == 0);
+ bool bQuiet = impl_->bQuiet_ || !bMaster;
+ CommandLineCommonOptionsHolder optionsHolder;
try
{
optionsHolder.initOptions();