Improve file name option help
authorTeemu Murtola <teemu.murtola@gmail.com>
Mon, 20 Jan 2014 19:17:42 +0000 (21:17 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 21 Jan 2014 03:42:28 +0000 (04:42 +0100)
- Add brackets for cases where the file name is actually optional.
- Add [...] for cases where multiple file names can be specified.

As supporting changes, extend the options machinery to be able to get
this information for the options, and fix an issue in the table
formatter that was causing some ugly formatting.

Related to #969.

Change-Id: I5b38d7ac6d7c58c3decce64ddfe60fff0a5797ed

12 files changed:
src/gromacs/commandline/cmdlinehelpwriter.cpp
src/gromacs/commandline/tests/cmdlinehelpwriter.cpp
src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesLongFileOptions.xml
src/gromacs/commandline/tests/refdata/CommandLineHelpWriterTest_HandlesOptionTypes.xml
src/gromacs/onlinehelp/helpformat.cpp
src/gromacs/onlinehelp/tests/helpformat.cpp
src/gromacs/onlinehelp/tests/refdata/TextTableFormatterTest_HandlesOverflowingLines.xml
src/gromacs/options/abstractoption.cpp
src/gromacs/options/abstractoption.h
src/gromacs/options/abstractoptionstorage.h
src/gromacs/options/optionflags.h
src/gromacs/options/optionstoragetemplate.h

index 1144f1e54fad50bf47c503d10e251072926b6a67..e3d404a186f00600e427edc24ecb87eeaefdfb38 100644 (file)
@@ -306,7 +306,6 @@ fileOptionFlagsAsString(const FileNameOptionInfo &option, bool bAbbrev)
     {
         type += bAbbrev ? ", Lib." : ", Library";
     }
-    // TODO: Add a tag for options that accept multiple files.
     return type;
 }
 
@@ -384,6 +383,14 @@ void OptionsExportFormatter::formatFileOption(
 {
     const bool  bAbbrev = (context.outputFormat() == eHelpOutputFormat_Console);
     std::string value("<" + option.type() + ">");
+    if (option.maxValueCount() != 1)
+    {
+        value += " [...]";
+    }
+    if (option.minValueCount() == 0)
+    {
+        value = "[" + value + "]";
+    }
     std::string defaultValue(defaultOptionValue(option));
     std::string info = "(" + fileOptionFlagsAsString(option, bAbbrev) + ")";
     if (!defaultValue.empty())
index 1bad19b1b761d16b0a262edbcbdd35df5b02f321..1a4b4d463dcbd58e81a806000494b328a7d518fd 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014, 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.
@@ -126,6 +126,10 @@ TEST_F(CommandLineHelpWriterTest, HandlesOptionTypes)
                           .description("Input file description")
                           .filetype(eftTrajectory).inputFile().required()
                           .defaultBasename("traj"));
+    options.addOption(FileNameOption("mult")
+                          .description("Multiple file description")
+                          .filetype(eftTrajectory).inputFile().multiValue()
+                          .defaultBasename("traj"));
     options.addOption(FileNameOption("lib")
                           .description("Library file description")
                           .filetype(eftGenericData).inputFile().libraryFile()
index 34bc51f4f5887e654c91057ca0094472d566d8e8..f04be2aece597e46eb8b913af0e719969ae1abf6 100644 (file)
@@ -8,10 +8,12 @@ FILE OPTIONS
      File name option with a long value: xtc trr cpt trj gro g96 pdb g87 tng
  -f2    <.xtc/.trr/...> (path/to/long/trajectory.xtc) (Input)
      File name option with a long value: xtc trr cpt trj gro g96 pdb g87 tng
- -lib   <.xtc/.trr/...> (path/to/long/trajectory/name.xtc) (Input, Opt., Lib.) File name option with a long value and type: xtc trr cpt trj gro g96 pdb g87 tng
- -longfileopt <.dat> (deffile.dat) (Input, Opt.)
+ -lib   [<.xtc/.trr/...>] (path/to/long/trajectory/name.xtc) (Input, Opt., Lib.)
+     File name option with a long value and type: xtc trr cpt trj gro g96 pdb
+     g87 tng
+ -longfileopt [<.dat>] (deffile.dat) (Input, Opt.)
      File name option with a long name
- -longfileopt2 <.dat> (path/to/long/file/name.dat) (Input, Opt., Lib.)
+ -longfileopt2 [<.dat>] (path/to/long/file/name.dat) (Input, Opt., Lib.)
      File name option with multiple long fields
 
 ]]></String>
index 01d693848e692da589d51658478a1e0406fa4b9d..c4bb5f2748c15dc3c4053e3335b354a07896e91b 100644 (file)
@@ -6,8 +6,10 @@ FILE OPTIONS
 
  -f     <.xtc/.trr/...> (traj.xtc) (Input)
      Input file description: xtc trr cpt trj gro g96 pdb g87 tng
- -lib   <.dat>   (libdata.dat) (Input, Opt., Lib.) Library file description
- -io    <.dat>   (inout.dat) (In/Out, Opt.) Input/Output file description
+ -mult  [<.xtc/.trr/...> [...]] (traj.xtc) (Input, Opt.)
+     Multiple file description: xtc trr cpt trj gro g96 pdb g87 tng
+ -lib   [<.dat>] (libdata.dat) (Input, Opt., Lib.) Library file description
+ -io    [<.dat>] (inout.dat) (In/Out, Opt.) Input/Output file description
  -o     <.xvg>   (Output, Opt.) Output file description
 
 OPTIONS
index 88fb03aea558db4d24b6ae1829828cc5648588ca..e98f6a63a9e5192c4617b6bc2d3193a8b7251e45 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014, 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.
@@ -337,7 +337,7 @@ std::string TextTableFormatter::formatRow()
                 const int overflow = static_cast<int>(lines[line].length()) - currentWidth;
                 if (overflow > 0)
                 {
-                    if (overflow > columnWidth)
+                    if (overflow > columnWidth && column->bWrap_)
                     {
                         columnLines.push_back(std::string());
                         continue;
index 74a77b7aa780334fd1b4d73acf3880a11ef4aed0..b7a03e94ac68ba7b9a92b30322e10652ae8b93e4 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014, 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.
@@ -135,6 +135,12 @@ TEST_F(TextTableFormatterTest, HandlesOverflowingLines)
     formatter_.setColumnFirstLineOffset(2, 2);
     formatter_.addColumnLine(3, g_wrapText2);
     checkText(formatter_.formatRow(), "FormattedRow3");
+    // Test a case where a column value overflows even the next column.
+    formatter_.addColumnLine(0, "foobarfoobar");
+    formatter_.addColumnLine(1, "barfoobarfoo");
+    formatter_.addColumnLine(2, g_wrapText);
+    formatter_.addColumnLine(3, g_wrapText2);
+    checkText(formatter_.formatRow(), "FormattedRow4");
 }
 
 TEST_F(TextTableFormatterTest, HandlesLastColumnFolding)
index d4a44b43f56ba241c3d8f811e9f2316c52a35b02..25ad209d62a46050e874dfbed54fc345540c840a 100644 (file)
@@ -21,5 +21,11 @@ foobar                   A quick brown
           A quick brown  over the lazy
           fox jumps over dog
           the lazy dog
+]]></String>
+  <String Name="FormattedRow4"><![CDATA[
+foobarfoobar barfoobarfoo A quick brown
+          A quick brown  fox jumps
+          fox jumps over over the lazy
+          the lazy dog   dog
 ]]></String>
 </ReferenceData>
index d0623ad69d0aeea8e89d0d93d88939f88681bc11..0db9950f985cb337ae7324ad05e71ad457f1a9a7 100644 (file)
@@ -209,6 +209,20 @@ bool OptionInfo::isRequired() const
     return option().isRequired();
 }
 
+int OptionInfo::minValueCount() const
+{
+    if (option().defaultValueIfSetExists())
+    {
+        return 0;
+    }
+    return option().minValueCount();
+}
+
+int OptionInfo::maxValueCount() const
+{
+    return option().maxValueCount();
+}
+
 const std::string &OptionInfo::name() const
 {
     return option().name();
@@ -230,6 +244,11 @@ std::string OptionInfo::formatDescription() const
     return description;
 }
 
+std::string OptionInfo::formatDefaultValueIfSet() const
+{
+    return option().formatDefaultValueIfSet();
+}
+
 int OptionInfo::valueCount() const
 {
     return option().valueCount();
@@ -240,9 +259,4 @@ std::string OptionInfo::formatValue(int i) const
     return option().formatValue(i);
 }
 
-std::string OptionInfo::formatDefaultValueIfSet() const
-{
-    return option().formatDefaultValueIfSet();
-}
-
 } // namespace gmx
index 8a9837b5b441745320f127602b7d731172bdba24..f92997371a3d4db7135d368977e74f7bfacb71e8 100644 (file)
@@ -441,16 +441,16 @@ class OptionInfo
         bool isHidden() const;
         //! Returns true if the option is required.
         bool isRequired() const;
+        //! Returns the minimum number of values that this option accepts.
+        int minValueCount() const;
+        //! Returns the maximum number of values that this option accepts.
+        int maxValueCount() const;
         //! Returns the name of the option.
         const std::string &name() const;
         //! Returns the type of the option as a string.
         std::string type() const;
         //! Returns the description of the option.
         std::string formatDescription() const;
-        //! Returns the number of values given for the option.
-        int valueCount() const;
-        //! Returns the i'th value of the option as a string.
-        std::string formatValue(int i) const;
         /*! \brief
          * Returns the default value if set for the option as a string.
          *
@@ -458,6 +458,11 @@ class OptionInfo
          */
         std::string formatDefaultValueIfSet() const;
 
+        //! Returns the number of values given for the option.
+        int valueCount() const;
+        //! Returns the i'th value of the option as a string.
+        std::string formatValue(int i) const;
+
     protected:
         /*! \cond libapi */
         /*! \brief
index 791c4edea06f63f65049cf5dc3ae9385fca4b51f..9cb9ff543e6e66ade451124b3f1a70c492381e67 100644 (file)
@@ -109,6 +109,14 @@ class AbstractOptionStorage
         //! Returns the description of the option set by the calling code.
         const std::string &description() const { return descr_; }
 
+        //! Returns true if defaultValueIfSet() value is specified.
+        bool defaultValueIfSetExists() const
+        { return hasFlag(efOption_DefaultValueIfSetExists); }
+        //! Returns the minimum number of values required in one set.
+        int minValueCount() const { return minValueCount_; }
+        //! Returns the maximum allowed number of values in one set (-1 = no limit).
+        int maxValueCount() const { return maxValueCount_; }
+
         /*! \brief
          * Returns an option info object corresponding to this option.
          */
@@ -221,10 +229,6 @@ class AbstractOptionStorage
         //! Clears the given flag.
         void clearFlag(OptionFlag flag) { return flags_.clear(flag); }
 
-        //! Returns the minimum number of values required in one set.
-        int minValueCount() const { return minValueCount_; }
-        //! Returns the maximum allowed number of values in one set (-1 = no limit).
-        int maxValueCount() const { return maxValueCount_; }
         /*! \brief
          * Sets a new minimum number of values required in one set.
          *
index 41a6514e4f4300cf22c996978c4185617c8707d8..5a4ff6399b42411315ade14685c8a8c1b772a21d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2014, 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.
@@ -69,7 +69,7 @@ enum OptionFlag
     //! The current value of the option is a programmatic default value.
     efOption_HasDefaultValue            = 1<<1,
     //! An explicit default value has been provided for the option.
-    efOption_ExplicitDefaultValue      = 1<<2,
+    efOption_ExplicitDefaultValue       = 1<<2,
     /*! \brief
      * Next assignment to the option clears old values.
      *
@@ -89,6 +89,8 @@ enum OptionFlag
      * \see AbstractOption::setVector()
      */
     efOption_Vector                     = 1<<8,
+    //! %Option has a defaultValueIfSet() specified.
+    efOption_DefaultValueIfSetExists    = 1<<11,
     //! %Option does not support default values.
     efOption_NoDefaultValue             = 1<<9,
     /*! \brief
index 3085a4191092bd6c0d39d11af50035628dcf09e6..dae027c79ad8a08309ba1cd3b435b4b92eb4c08e 100644 (file)
@@ -475,6 +475,7 @@ void OptionStorageTemplate<T>::setDefaultValueIfSet(const T &value)
     {
         GMX_THROW(APIError("defaultValueIfSet() is not supported with allowMultiple()"));
     }
+    setFlag(efOption_DefaultValueIfSetExists);
     defaultValueIfSet_.reset(new T(value));
 }