Move Options::setDescription() elsewhere
authorTeemu Murtola <teemu.murtola@gmail.com>
Fri, 17 Jul 2015 04:05:53 +0000 (07:05 +0300)
committerRoland Schulz <roland@rschulz.eu>
Sat, 18 Jul 2015 07:07:16 +0000 (09:07 +0200)
Pass the help text for programs using other means, clarifying
responsibilities in the code.  Now Options is closer to being just a
container of options.  Further refactoring to follow.

Change-Id: I398ebef7884d88111ab1bddcd9397882835b39b4

28 files changed:
share/template/template.cpp
src/gromacs/commandline/cmdlinehelpmodule.cpp
src/gromacs/commandline/cmdlinehelpwriter.cpp
src/gromacs/commandline/cmdlinehelpwriter.h
src/gromacs/commandline/cmdlineoptionsmodule.cpp
src/gromacs/commandline/cmdlineoptionsmodule.h
src/gromacs/commandline/pargs.cpp
src/gromacs/commandline/tests/cmdlinehelpmodule.cpp
src/gromacs/commandline/tests/cmdlinehelpwriter.cpp
src/gromacs/commandline/tests/cmdlinemodulemanagertest.h
src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesHelpText.xml [new file with mode: 0644]
src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesMultipleSections.xml [deleted file]
src/gromacs/gmxpreprocess/insert-molecules.cpp
src/gromacs/options/options-impl.h
src/gromacs/options/options.cpp
src/gromacs/options/options.h
src/gromacs/trajectoryanalysis/analysissettings-impl.h
src/gromacs/trajectoryanalysis/analysissettings.cpp
src/gromacs/trajectoryanalysis/analysissettings.h
src/gromacs/trajectoryanalysis/cmdlinerunner.cpp
src/gromacs/trajectoryanalysis/modules/angle.cpp
src/gromacs/trajectoryanalysis/modules/distance.cpp
src/gromacs/trajectoryanalysis/modules/freevolume.cpp
src/gromacs/trajectoryanalysis/modules/pairdist.cpp
src/gromacs/trajectoryanalysis/modules/rdf.cpp
src/gromacs/trajectoryanalysis/modules/sasa.cpp
src/gromacs/trajectoryanalysis/modules/select.cpp
src/gromacs/trajectoryanalysis/tests/test_selection.cpp

index 6ef9e466b5764566615f7be8b006efbea087ec71..3cb55d5e89183b6b5586e9a522e12d6a02d8e7ae 100644 (file)
@@ -101,7 +101,7 @@ AnalysisTemplate::initOptions(Options                    *options,
         "analysis groups."
     };
 
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     options->addOption(FileNameOption("o")
                            .filetype(eftPlot).outputFile()
index 11237e21ffdab389edc833887e825cc392b6d43e..cabe8f1b7a4507c06d13d032352f1f4d2ae654ec 100644 (file)
@@ -289,11 +289,15 @@ void RootHelpTopic::writeHelp(const HelpWriterContext &context) const
         }
         cmdlineContext->setModuleDisplayName(helpModule_.binaryName_);
         optionsHolder.initOptions();
-        Options &options = *optionsHolder.options();
-        options.setDescription(RootHelpText::text);
+        Options                    &options = *optionsHolder.options();
+        ConstArrayRef<const char *> helpText;
+        if (context.outputFormat() != eHelpOutputFormat_Console)
+        {
+            helpText = RootHelpText::text;
+        }
         // TODO: Add <command> [<args>] into the synopsis.
         CommandLineHelpWriter(options)
-            .setShowDescriptions(context.outputFormat() != eHelpOutputFormat_Console)
+            .setHelpText(helpText)
             .writeHelp(*cmdlineContext);
     }
     if (context.outputFormat() == eHelpOutputFormat_Console)
index 69448c4bd780d8ae8a8c3d1f44ae1769f0639602..4cda5726782febd7a9ade586a22e492c48fd3b33 100644 (file)
@@ -73,69 +73,6 @@ namespace
 //! \addtogroup module_commandline
 //! \{
 
-/********************************************************************
- * DescriptionsFormatter
- */
-
-class DescriptionsFormatter : public OptionsVisitor
-{
-    public:
-        /*! \brief
-         * Creates a new description formatter.
-         *
-         * \param[in] context   Help context to use to write the help.
-         */
-        explicit DescriptionsFormatter(const HelpWriterContext &context)
-            : context_(context), title_(NULL), bDidOutput_(false)
-        {
-        }
-
-        //! Formats all section descriptions from a given options.
-        void format(const Options &options, const char *title)
-        {
-            title_      = title;
-            bDidOutput_ = false;
-            visitSubSection(options);
-            if (bDidOutput_)
-            {
-                context_.outputFile().writeLine();
-            }
-        }
-
-        //! Formats the description for a single subsection and handles recursion.
-        virtual void visitSubSection(const Options &section);
-        // This method is not used and never called.
-        virtual void visitOption(const OptionInfo & /*option*/) {}
-
-    private:
-        const HelpWriterContext &context_;
-        const char              *title_;
-        bool                     bDidOutput_;
-
-        GMX_DISALLOW_COPY_AND_ASSIGN(DescriptionsFormatter);
-};
-
-void DescriptionsFormatter::visitSubSection(const Options &section)
-{
-    if (!section.description().empty())
-    {
-        if (bDidOutput_)
-        {
-            context_.outputFile().writeLine();
-        }
-        else if (title_ != NULL)
-        {
-            context_.writeTitle(title_);
-        }
-        // TODO: Print title for the section?
-        context_.writeTextBlock(section.description());
-        bDidOutput_ = true;
-    }
-
-    OptionsIterator iterator(section);
-    iterator.acceptSubSections(this);
-}
-
 /********************************************************************
  * IOptionsFormatter
  */
@@ -578,17 +515,16 @@ class CommandLineHelpWriter::Impl
 
         //! Options object to use for generating help.
         const Options               &options_;
+        //! Help text.
+        std::string                  helpText_;
         //! List of bugs/knows issues.
         ConstArrayRef<const char *>  bugs_;
         //! Time unit to show in descriptions.
         std::string                  timeUnit_;
-        //! Whether to write descriptions to output.
-        bool                         bShowDescriptions_;
 };
 
 CommandLineHelpWriter::Impl::Impl(const Options &options)
-    : options_(options), timeUnit_(TimeUnitManager().timeUnitAsString()),
-      bShowDescriptions_(false)
+    : options_(options), timeUnit_(TimeUnitManager().timeUnitAsString())
 {
 }
 
@@ -622,16 +558,23 @@ CommandLineHelpWriter::~CommandLineHelpWriter()
 }
 
 CommandLineHelpWriter &
-CommandLineHelpWriter::setShowDescriptions(bool bSet)
+CommandLineHelpWriter::setTimeUnitString(const char *timeUnit)
 {
-    impl_->bShowDescriptions_ = bSet;
+    impl_->timeUnit_ = timeUnit;
     return *this;
 }
 
 CommandLineHelpWriter &
-CommandLineHelpWriter::setTimeUnitString(const char *timeUnit)
+CommandLineHelpWriter::setHelpText(const std::string &help)
 {
-    impl_->timeUnit_ = timeUnit;
+    impl_->helpText_ = help;
+    return *this;
+}
+
+CommandLineHelpWriter &
+CommandLineHelpWriter::setHelpText(const ConstArrayRef<const char *> &help)
+{
+    impl_->helpText_ = joinStrings(help, "\n");
     return *this;
 }
 
@@ -669,10 +612,11 @@ void CommandLineHelpWriter::writeHelp(const CommandLineHelpContext &context)
         synopsisFormatter.finish();
     }
 
-    if (impl_->bShowDescriptions_)
+    if (!impl_->helpText_.empty())
     {
-        DescriptionsFormatter descriptionFormatter(writerContext);
-        descriptionFormatter.format(impl_->options_, "Description");
+        writerContext.writeTitle("Description");
+        writerContext.writeTextBlock(impl_->helpText_);
+        writerContext.outputFile().writeLine();
     }
     CommonFormatterData    common(impl_->timeUnit_.c_str());
     OptionsListFormatter   formatter(writerContext, common, "Options");
index 04fff38c9c7ae09fd20de267232513bbd1ec2b67..93725fa3c86c5361ad5cc21ffc84766669063288 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -43,6 +43,8 @@
 #ifndef GMX_COMMANDLINE_CMDLINEHELPWRITER_H
 #define GMX_COMMANDLINE_CMDLINEHELPWRITER_H
 
+#include <string>
+
 #include "gromacs/utility/classhelpers.h"
 
 namespace gmx
@@ -54,7 +56,7 @@ class Options;
 template <typename T> class ConstArrayRef;
 
 /*! \brief
- * Writes help information for Options in ascii format.
+ * Writes help information for Options.
  *
  * \inpublicapi
  * \ingroup module_commandline
@@ -70,10 +72,6 @@ class CommandLineHelpWriter
         explicit CommandLineHelpWriter(const Options &options);
         ~CommandLineHelpWriter();
 
-        /*! \brief
-         * Sets whether long descriptions for sections are shown in the help.
-         */
-        CommandLineHelpWriter &setShowDescriptions(bool bShow);
         /*! \brief
          * Sets time unit to show in descriptions.
          *
@@ -85,7 +83,20 @@ class CommandLineHelpWriter
          * If not called, uses a default "ps".
          */
         CommandLineHelpWriter &setTimeUnitString(const char *timeUnit);
-
+        /*! \brief
+         * Sets the help text to print as description.
+         *
+         * \param[in] help  Help text to show.
+         * \throws    std::bad_alloc if out of memory.
+         *
+         * If `help` is empty, or this method is not called, only a list of
+         * options is printed.
+         * Formatting for the help text is described on \ref page_onlinehelp.
+         */
+        CommandLineHelpWriter &setHelpText(const std::string &help);
+        //! \copydoc setHelpText(const std::string &)
+        CommandLineHelpWriter &
+        setHelpText(const ConstArrayRef<const char *> &help);
         /*! \brief
          * Sets the list of known bugs/limitations.
          *
index 2b560f161c5a6051d22c84c13d11f9f92b45eaa8..e8249492e8cb8ceb851101cb60818f28f484eb31 100644 (file)
@@ -50,7 +50,9 @@
 #include "gromacs/commandline/cmdlineparser.h"
 #include "gromacs/options/filenameoptionmanager.h"
 #include "gromacs/options/options.h"
+#include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/stringutil.h"
 
 namespace gmx
 {
@@ -58,6 +60,24 @@ namespace gmx
 namespace
 {
 
+/********************************************************************
+ * CommandLineOptionsModuleSettings
+ */
+
+class CommandLineOptionsModuleSettings : public ICommandLineOptionsModuleSettings
+{
+    public:
+        const std::string &helpText() const { return helpText_; }
+
+        virtual void setHelpText(const ConstArrayRef<const char *> &help)
+        {
+            helpText_ = joinStrings(help, "\n");
+        }
+
+    private:
+        std::string helpText_;
+};
+
 /********************************************************************
  * CommandLineOptionsModule
  */
@@ -122,10 +142,11 @@ void CommandLineOptionsModule::writeHelp(const CommandLineHelpContext &context)
         moduleGuard.reset(factory_());
         module = moduleGuard.get();
     }
-    Options options(name(), shortDescription());
-    module->initOptions(&options);
+    Options                          options(name(), shortDescription());
+    CommandLineOptionsModuleSettings settings;
+    module->initOptions(&options, &settings);
     CommandLineHelpWriter(options)
-        .setShowDescriptions(true)
+        .setHelpText(settings.helpText())
         .writeHelp(context);
 }
 
@@ -136,7 +157,8 @@ void CommandLineOptionsModule::parseOptions(int argc, char *argv[])
 
     options.addManager(&fileoptManager);
 
-    module_->initOptions(&options);
+    CommandLineOptionsModuleSettings settings;
+    module_->initOptions(&options, &settings);
     {
         CommandLineParser parser(&options);
         parser.parse(&argc, argv);
@@ -147,6 +169,14 @@ void CommandLineOptionsModule::parseOptions(int argc, char *argv[])
 
 }   // namespace
 
+/********************************************************************
+ * ICommandLineOptionsModuleSettings
+ */
+
+ICommandLineOptionsModuleSettings::~ICommandLineOptionsModuleSettings()
+{
+}
+
 /********************************************************************
  * ICommandLineOptionsModule
  */
index f5a905637331c4e8cfe809bc5c24f1f6aa2ae83a..ae7c004d013224c76fd80c6f2e724de2b46849cf 100644 (file)
 namespace gmx
 {
 
+template <typename T> class ConstArrayRef;
+
 class CommandLineModuleManager;
 class ICommandLineModule;
 class Options;
 
+/*! \brief
+ * Settings to pass information between a CommandLineOptionsModule and generic
+ * code that runs it.
+ *
+ * \inpublicapi
+ * \ingroup module_commandline
+ */
+class ICommandLineOptionsModuleSettings
+{
+    public:
+        /*! \brief
+         * Sets the help text for the module from string array.
+         *
+         * \param[in] help  String array to set as the description.
+         * \throws    std::bad_alloc if out of memory.
+         *
+         * Formatting for the help text is described on \ref page_onlinehelp.
+         *
+         * Example usage:
+         * \code
+           const char *const desc[] = {
+               "This is the description",
+               "for the options"
+           };
+
+           settings->setHelpText(desc);
+           \endcode
+         */
+        virtual void setHelpText(const ConstArrayRef<const char *> &help) = 0;
+
+    protected:
+        // Disallow deletion through the interface.
+        // (no need for the virtual, but some compilers warn otherwise)
+        virtual ~ICommandLineOptionsModuleSettings();
+};
+
 /*! \brief
  * Module that can be run from a command line and uses gmx::Options for
  * argument processing.
@@ -182,6 +220,8 @@ class ICommandLineOptionsModule
          * Initializes command-line arguments understood by the module.
          *
          * \param[in,out] options  Options object to add the options to.
+         * \param[in,out] settings Settings to communicate information
+         *     to/from generic code running the module.
          *
          * When running the module, this method is called after init().
          * When printing help, there is no call to init(), and this is the only
@@ -190,7 +230,8 @@ class ICommandLineOptionsModule
          * the module to \p options.  Output values from options should be
          * stored in member variables.
          */
-        virtual void initOptions(Options *options)             = 0;
+        virtual void initOptions(Options                           *options,
+                                 ICommandLineOptionsModuleSettings *settings) = 0;
         /*! \brief
          * Called after all option values have been set.
          *
@@ -203,7 +244,7 @@ class ICommandLineOptionsModule
          * If the module needs to call, e.g., Options::isSet(), this is the
          * place to do that.
          */
-        virtual void optionsFinished(Options *options)         = 0;
+        virtual void optionsFinished(Options *options) = 0;
 
         /*! \brief
          * Runs the module.
index 95af8735b70a94fec10328ef034c646b157e41d4..6daf7d554bceab34c6c1c401424a4ec44d5e4b85 100644 (file)
@@ -498,7 +498,6 @@ gmx_bool parse_common_args(int *argc, char *argv[], unsigned long Flags,
         fileOptManager.disableInputOptionChecking(
                 FF(PCA_NOT_READ_NODE) || FF(PCA_DISABLE_INPUT_FILE_CHECKING));
         options.addManager(&fileOptManager);
-        options.setDescription(gmx::constArrayRefFromArray<const char *>(desc, ndesc));
 
         if (FF(PCA_CAN_SET_DEFFNM))
         {
@@ -567,7 +566,7 @@ gmx_bool parse_common_args(int *argc, char *argv[], unsigned long Flags,
                                "Help output should be handled higher up and "
                                "only get called only on the master rank");
             gmx::CommandLineHelpWriter(options)
-                .setShowDescriptions(true)
+                .setHelpText(gmx::constArrayRefFromArray<const char *>(desc, ndesc))
                 .setTimeUnitString(timeUnitManager.timeUnitAsString())
                 .setKnownIssues(gmx::constArrayRefFromArray(bugs, nbugs))
                 .writeHelp(*context);
index 5fada52c35de53dd3fec1d0fd73e1095e89bb9fe..ba62e55e0393cc399472320a3b5e68b214008497 100644 (file)
@@ -107,13 +107,14 @@ TEST_F(CommandLineHelpModuleTest, PrintsHelpOnTopic)
  *
  * \ingroup module_commandline
  */
-void initOptionsBasic(gmx::Options *options)
+void initOptionsBasic(gmx::Options                           *options,
+                      gmx::ICommandLineOptionsModuleSettings *settings)
 {
     const char *const desc[] = {
         "Sample description",
         "for testing [THISMODULE]."
     };
-    options->setDescription(desc);
+    settings->setHelpText(desc);
     options->addOption(gmx::IntegerOption("int"));
 }
 
@@ -143,8 +144,8 @@ TEST_F(CommandLineHelpModuleTest, ExportsHelp)
     MockHelpTopic &topic2 = addHelpTopic("topic2", "Another topic");
     using ::testing::_;
     using ::testing::Invoke;
-    EXPECT_CALL(mod1, initOptions(_)).WillOnce(Invoke(&initOptionsBasic));
-    EXPECT_CALL(mod2, initOptions(_));
+    EXPECT_CALL(mod1, initOptions(_, _)).WillOnce(Invoke(&initOptionsBasic));
+    EXPECT_CALL(mod2, initOptions(_, _));
     EXPECT_CALL(topic1, writeHelp(_));
     EXPECT_CALL(sub1, writeHelp(_));
     EXPECT_CALL(sub2, writeHelp(_));
index 7d3a282e2e4ec6650a61bb8a52f69082caedd8be..886b0b0d18f8f95168d2b8cdb6d0a294c2eda5db 100644 (file)
@@ -56,6 +56,7 @@
 #include "gromacs/options/basicoptions.h"
 #include "gromacs/options/filenameoption.h"
 #include "gromacs/options/options.h"
+#include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/stringstream.h"
 
 #include "testutils/stringtest.h"
@@ -246,32 +247,22 @@ TEST_F(CommandLineHelpWriterTest, HandlesSelectionOptions)
 #endif
 
 /*
- * Tests help printing for multiple sections.
+ * Tests help output using a help text.
  */
-TEST_F(CommandLineHelpWriterTest, HandlesMultipleSections)
+TEST_F(CommandLineHelpWriterTest, HandlesHelpText)
 {
-    using namespace gmx;
+    const char *const help[] = {
+        "Help text",
+        "for testing."
+    };
+    using gmx::IntegerOption;
 
-    Options options("test", "Main Title");
-    Options subSect1("subsect1", "Subsection 1 Title");
-    Options subSect2("subsect2", "Subsection 2 Title");
-    Options subSect3("subsect3", NULL);
-    options.addSubSection(&subSect1);
-    options.addSubSection(&subSect2);
-    options.addSubSection(&subSect3);
-    options.setDescription("Description for main section.");
-    subSect1.setDescription("Description for subsection 1.");
-    subSect2.setDescription("Description for subsection 2.");
-    subSect3.setDescription("Description for subsection 3.");
-    options.addOption(IntegerOption("main")
-                          .description("Option in main section"));
-    subSect1.addOption(IntegerOption("sub1")
-                           .description("Option in subsection 1"));
-    subSect2.addOption(IntegerOption("sub2")
-                           .description("Option in subsection 2"));
+    gmx::Options options(NULL, NULL);
+    options.addOption(IntegerOption("int").description("Integer option")
+                          .defaultValue(2));
 
-    CommandLineHelpWriter writer(options);
-    writer.setShowDescriptions(true);
+    gmx::CommandLineHelpWriter writer(options);
+    writer.setHelpText(help);
     checkHelp(&writer);
 }
 
index c41cc55bccf776b1e7076eebff89aa99bb90b508..deb27ddb3a50325d1ec50b6e92aefc575c49f41d 100644 (file)
@@ -108,7 +108,7 @@ class MockOptionsModule : public gmx::ICommandLineOptionsModule
         ~MockOptionsModule();
 
         MOCK_METHOD1(init, void(gmx::CommandLineModuleSettings *settings));
-        MOCK_METHOD1(initOptions, void(gmx::Options *options));
+        MOCK_METHOD2(initOptions, void(gmx::Options *options, gmx::ICommandLineOptionsModuleSettings *settings));
         MOCK_METHOD1(optionsFinished, void(gmx::Options *options));
         MOCK_METHOD0(run, int());
 };
diff --git a/src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesHelpText.xml b/src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesHelpText.xml
new file mode 100644 (file)
index 0000000..5ecad2b
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+  <String Name="HelpText"><![CDATA[
+SYNOPSIS
+
+gmx [-int <int>]
+
+DESCRIPTION
+
+Help text for testing.
+
+OPTIONS
+
+Other options:
+
+ -int    <int>              (2)
+           Integer option
+
+]]></String>
+</ReferenceData>
diff --git a/src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesMultipleSections.xml b/src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesMultipleSections.xml
deleted file mode 100644 (file)
index baa4db0..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0"?>
-<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
-<ReferenceData>
-  <String Name="HelpText"><![CDATA[
-SYNOPSIS
-
-gmx [-sub1 <int>] [-sub2 <int>] [-main <int>]
-
-DESCRIPTION
-
-Description for main section.
-
-Description for subsection 1.
-
-Description for subsection 2.
-
-Description for subsection 3.
-
-OPTIONS
-
-Other options:
-
- -sub1   <int>
-           Option in subsection 1
- -sub2   <int>
-           Option in subsection 2
- -main   <int>
-           Option in main section
-
-]]></String>
-</ReferenceData>
index 34421a3c1037cae2d0c536663cd0505b331e1c59..b4f77af2b32f1a6bee8332a1ab30182876ee1a6b 100644 (file)
@@ -318,7 +318,8 @@ class InsertMolecules : public ICommandLineOptionsModule
         {
         }
 
-        virtual void initOptions(Options *options);
+        virtual void initOptions(Options                           *options,
+                                 ICommandLineOptionsModuleSettings *settings);
         virtual void optionsFinished(Options *options);
 
         virtual int run();
@@ -339,7 +340,8 @@ class InsertMolecules : public ICommandLineOptionsModule
         int         enumRot_;
 };
 
-void InsertMolecules::initOptions(Options *options)
+void InsertMolecules::initOptions(Options                           *options,
+                                  ICommandLineOptionsModuleSettings *settings)
 {
     const char *const desc[] = {
         "[THISMODULE] inserts [TT]-nmol[tt] copies of the system specified in",
@@ -376,7 +378,7 @@ void InsertMolecules::initOptions(Options *options)
         "[TT]-try[tt] and [TT]-rot[tt] work as in the default mode (see above)."
     };
 
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     // TODO: Replace use of legacyType.
     options->addOption(FileNameOption("f")
index 3fba6da02ad8efc80378ae11bceb42d12fa4fd30..a5294c04209ee8fa217cd93071da93a174f47dad 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -108,10 +108,6 @@ class Options::Impl
 
         //! Name for the Options object.
         std::string             name_;
-        //! Description title for the Options object.
-        std::string             title_;
-        //! Full description for the Options object.
-        std::string             description_;
         /*! \brief
          * Option managers set for this collection.
          *
index 4048addbf346a6b25c10758454135916c2e3a5a6..c0cff702033c691e79be4913cb2c05356117446b 100644 (file)
@@ -67,8 +67,8 @@ IOptionManager::~IOptionManager()
  * Options::Impl
  */
 
-Options::Impl::Impl(const char *name, const char *title)
-    : name_(name != NULL ? name : ""), title_(title != NULL ? title : ""),
+Options::Impl::Impl(const char *name, const char * /*title*/)
+    : name_(name != NULL ? name : ""),
       parent_(NULL)
 {
 }
@@ -137,25 +137,6 @@ const std::string &Options::name() const
     return impl_->name_;
 }
 
-const std::string &Options::title() const
-{
-    return impl_->title_;
-}
-
-const std::string &Options::description() const
-{
-    return impl_->description_;
-}
-
-void Options::setDescription(const std::string &desc)
-{
-    impl_->description_ = desc;
-}
-
-void Options::setDescription(const ConstArrayRef<const char *> &descArray)
-{
-    impl_->description_ = joinStrings(descArray, "\n");
-}
 
 void Options::addManager(IOptionManager *manager)
 {
index 452f96c6de00807a512421d7fe3c55377772df21..d62319b0a0626bea7b7c814dec5892f4bacab023 100644 (file)
@@ -55,8 +55,6 @@
 namespace gmx
 {
 
-template <typename T> class ConstArrayRef;
-
 class AbstractOption;
 class OptionsAssigner;
 class OptionsIterator;
@@ -134,43 +132,6 @@ class Options
 
         //! Returns the short name of the option collection.
         const std::string &name() const;
-        //! Returns the title of the option collection.
-        const std::string &title() const;
-        //! Returns the full description of the option collection.
-        const std::string &description() const;
-
-        /*! \brief
-         * Sets the full description of the option collection.
-         *
-         * \param[in] desc  String to set as the description.
-         *
-         * This overload is mainly useful if the description is very short.
-         * Currently this is mostly the case in unit testing.
-         */
-        void setDescription(const std::string &desc);
-        /*! \brief
-         * Sets the full description of the option collection from string array.
-         *
-         * \param[in] descArray  String array to set as the description.
-         *
-         * All strings in `descArray` are concatenated to form the description.
-         * Spaces are inserted between strings if they are missing.
-         *
-         * Example usage:
-         * \code
-           const char *const desc[] = {
-               "This is the description",
-               "for the options"
-           };
-
-           gmx::Options options(NULL, NULL);
-           options.setDescription(desc);
-           \endcode
-         *
-         * To use this overload, you must also include
-         * `gromacs/utility/arrayref.h`.
-         */
-        void setDescription(const ConstArrayRef<const char *> &descArray);
 
         /*! \brief
          * Adds an option manager.
index b42defaaa610f6e899c34e627f51a58e96a3fa9a..0939204c8f1941218f11eb4a39878444e7abdbbc 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -42,6 +42,8 @@
 #ifndef GMX_TRAJECTORYANALYSIS_ANALYSISSETTINGS_IMPL_H
 #define GMX_TRAJECTORYANALYSIS_ANALYSISSETTINGS_IMPL_H
 
+#include <string>
+
 #include "gromacs/analysisdata/modules/plot.h"
 #include "gromacs/options/timeunitmanager.h"
 #include "gromacs/trajectoryanalysis/analysissettings.h"
@@ -73,6 +75,9 @@ class TrajectoryAnalysisSettings::Impl
         bool                 bRmPBC;
         //! Whether to pass PBC information to the analysis module.
         bool                 bPBC;
+
+        //! Help text for the module.
+        std::string          helpText_;
 };
 
 } // namespace gmx
index da9031abb82b40b91daefafe620f3ba63d6f68c5..03689a8fca4658712fb3e1c0867765a685ce9271 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/topology/topology.h"
+#include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/smalloc.h"
+#include "gromacs/utility/stringutil.h"
 
 #include "analysissettings-impl.h"
 
@@ -161,6 +163,18 @@ TrajectoryAnalysisSettings::setFrameFlags(int frflags)
     impl_->frflags = frflags;
 }
 
+const std::string &
+TrajectoryAnalysisSettings::helpText() const
+{
+    return impl_->helpText_;
+}
+
+void
+TrajectoryAnalysisSettings::setHelpText(const ConstArrayRef<const char *> &help)
+{
+    impl_->helpText_ = joinStrings(help, "\n");
+}
+
 
 /********************************************************************
  * TopologyInformation
index 20383df9cd0fa39a8b858687617906be9e5ddaa4..ba2b6a1225af0870fb86e63045a2a616359774b8 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -43,6 +43,8 @@
 #ifndef GMX_TRAJECTORYANALYSIS_ANALYSISSETTINGS_H
 #define GMX_TRAJECTORYANALYSIS_ANALYSISSETTINGS_H
 
+#include <string>
+
 #include "gromacs/math/vectypes.h"
 #include "gromacs/options/timeunitmanager.h"
 #include "gromacs/utility/classhelpers.h"
@@ -52,6 +54,8 @@ struct t_topology;
 namespace gmx
 {
 
+template <typename T> class ConstArrayRef;
+
 class AnalysisDataPlotSettings;
 class Options;
 class TrajectoryAnalysisRunnerCommon;
@@ -218,6 +222,11 @@ class TrajectoryAnalysisSettings
          */
         void setFrameFlags(int frflags);
 
+        //! Returns the help text.
+        const std::string &helpText() const;
+        //! \copydoc ICommandLineOptionsModuleSettings::setHelpText(const std::string &)
+        void setHelpText(const ConstArrayRef<const char *> &help);
+
     private:
         class Impl;
 
index 339c0c7fc8903df46164a130765a650cb7485b01..5ac15b6281f04b4386ebe8ea77f95d6855d4a70f 100644 (file)
@@ -273,7 +273,7 @@ TrajectoryAnalysisCommandLineRunner::writeHelp(const CommandLineHelpContext &con
     selections.initOptions(&selectionOptions);
 
     CommandLineHelpWriter(options)
-        .setShowDescriptions(true)
+        .setHelpText(settings.helpText())
         .setTimeUnitString(settings.timeUnitManager().timeUnitAsString())
         .writeHelp(context);
 }
index a8a4e0a358fee5e45edf561c8d767f7b281afb31..8968c49690135fc1bb83325e75cab9b21639c1e3 100644 (file)
@@ -304,7 +304,7 @@ Angle::Angle()
 
 
 void
-Angle::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
+Angle::initOptions(Options *options, TrajectoryAnalysisSettings *settings)
 {
     static const char *const desc[] = {
         "[THISMODULE] computes different types of angles between vectors.",
@@ -359,7 +359,7 @@ Angle::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
     static const char *const cGroup2TypeEnum[] =
     { "none", "vector", "plane", "t0", "z", "sphnorm" };
 
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     options->addOption(FileNameOption("oav").filetype(eftPlot).outputFile()
                            .store(&fnAverage_).defaultBasename("angaver")
index 4b07d1483a4f5f81da6bba393b2f4a65d0c736bb..bc9fb9687eed8c046772211c9a262a5e7a72d8d4 100644 (file)
@@ -132,7 +132,7 @@ Distance::Distance()
 
 
 void
-Distance::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
+Distance::initOptions(Options *options, TrajectoryAnalysisSettings *settings)
 {
     static const char *const desc[] = {
         "[THISMODULE] calculates distances between pairs of positions",
@@ -156,7 +156,7 @@ Distance::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*
         "distances, use [gmx-pairdist]."
     };
 
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     options->addOption(FileNameOption("oav").filetype(eftPlot).outputFile()
                            .store(&fnAverage_).defaultBasename("distave")
index b489c2a933920764d1591ddb6e34087cd34a878a..a99215cffd6df62af3073d3fb686859f2b33f76f 100644 (file)
@@ -196,8 +196,7 @@ FreeVolume::initOptions(Options                    *options,
         "the terminal."
     };
 
-    // Add the descriptive text (program help text) to the options
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     // Add option for optional output file
     options->addOption(FileNameOption("o").filetype(eftPlot).outputFile()
index 37b2bbbef53e8281c8e5f9cb77eae47ce3086cbf..0d365ffa34be4257c474666b1cc80638c842f20e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -177,7 +177,7 @@ PairDistance::PairDistance()
 
 
 void
-PairDistance::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
+PairDistance::initOptions(Options *options, TrajectoryAnalysisSettings *settings)
 {
     static const char *const desc[] = {
         "[THISMODULE] calculates pairwise distances between one reference",
@@ -214,7 +214,7 @@ PairDistance::initOptions(Options *options, TrajectoryAnalysisSettings * /*setti
         "[gmx-distance] may be a more suitable tool."
     };
 
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     options->addOption(FileNameOption("o").filetype(eftPlot).outputFile().required()
                            .store(&fnDist_).defaultBasename("dist")
index 468b729873fb6c321d28f49e05b16183129eb276..448095bdf3f328534b285fab0212465ce88459b7 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -200,7 +200,7 @@ Rdf::Rdf()
 }
 
 void
-Rdf::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
+Rdf::initOptions(Options *options, TrajectoryAnalysisSettings *settings)
 {
     static const char *const desc[] = {
         "[THISMODULE] calculates radial distribution functions from one",
@@ -240,7 +240,7 @@ Rdf::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
         "i.e. the average number of particles within a distance r.[PAR]"
     };
 
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     options->addOption(FileNameOption("o").filetype(eftPlot).outputFile().required()
                            .store(&fnRdf_).defaultBasename("rdf")
index 674a5fa265aabb5bbe24e0b3c29a136022ce11ce..964910206941b4c7c53edf3f6c456aafd86455d5 100644 (file)
@@ -445,7 +445,7 @@ Sasa::initOptions(Options *options, TrajectoryAnalysisSettings *settings)
         "that are both too high."
     };
 
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     options->addOption(FileNameOption("o").filetype(eftPlot).outputFile().required()
                            .store(&fnArea_).defaultBasename("area")
index 443c4a129c7934aa0668eca5b4bfdfb68a350541..0239d188603c6ae2749689be43a94b3b631ce883 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -327,7 +327,7 @@ Select::Select()
 
 
 void
-Select::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
+Select::initOptions(Options *options, TrajectoryAnalysisSettings *settings)
 {
     static const char *const desc[] = {
         "[THISMODULE] writes out basic data about dynamic selections.",
@@ -391,7 +391,7 @@ Select::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
         "dynamic selections."
     };
 
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     options->addOption(FileNameOption("os").filetype(eftPlot).outputFile()
                            .store(&fnSize_).defaultBasename("size")
index e8153b6e2e3af9a2e68b580fa2e38e9709387158..c0868646e6f2d685ae1cf76dd0129406f10b7395 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -99,14 +99,14 @@ SelectionTester::printSelections()
 }
 
 void
-SelectionTester::initOptions(Options                   *options,
-                             TrajectoryAnalysisSettings * /*settings*/)
+SelectionTester::initOptions(Options                    *options,
+                             TrajectoryAnalysisSettings *settings)
 {
     static const char *const desc[] = {
         "This is a test program for selections."
     };
 
-    options->setDescription(desc);
+    settings->setHelpText(desc);
 
     options->addOption(SelectionOption("select").storeVector(&selections_)
                            .required().multiValue()