Fix HTML help and man pages for commands with dashes
authorTeemu Murtola <teemu.murtola@gmail.com>
Thu, 10 Jul 2014 03:39:59 +0000 (06:39 +0300)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Wed, 16 Jul 2014 04:08:13 +0000 (06:08 +0200)
Replace one case of "gmx-something" to "gmx something" conversion with
explicit construction of the latter from its component parts.
The other instance does not (easily) have the component parts available,
so only the first dash is removed when converting between
"gmx-something" and "gmx something". Add an assert for the condition
that this requires to remain functional.

Change-Id: I5bfbd1acae440af93b3b7b50a25d8782a7e60c8a

src/gromacs/commandline/cmdlinehelpmodule.cpp
src/gromacs/commandline/cmdlinemodulemanager.cpp

index 745e0c74108edce1534e5cf8618825094548685d..f1cc893b11f342659159fc4cd6d7b30df6be9e81 100644 (file)
@@ -41,7 +41,6 @@
  */
 #include "gromacs/commandline/cmdlinehelpmodule.h"
 
-#include <algorithm>
 #include <string>
 #include <vector>
 
@@ -619,7 +618,12 @@ void HelpExportHtml::exportModuleGroup(const char                *title,
     {
         const std::string     &tag(module->first);
         std::string            displayName(tag);
-        std::replace(displayName.begin(), displayName.end(), '-', ' ');
+        // TODO: This does not work if the binary name would contain a dash,
+        // but that is not currently the case.
+        size_t                 dashPos = displayName.find('-');
+        GMX_RELEASE_ASSERT(dashPos != std::string::npos,
+                           "There should always be at least one dash in the tag");
+        displayName[dashPos] = ' ';
         indexFile_->writeLine(formatString("<a href=\"%s.html\">%s</a> - %s<br>",
                                            tag.c_str(), displayName.c_str(),
                                            module->second));
@@ -739,8 +743,7 @@ void CommandLineHelpModuleImpl::exportHelp(HelpExportInterface *exporter) const
         {
             const char *const moduleName = module->first.c_str();
             std::string       tag(formatString("%s-%s", program, moduleName));
-            std::string       displayName(tag);
-            std::replace(displayName.begin(), displayName.end(), '-', ' ');
+            std::string       displayName(formatString("%s %s", program, moduleName));
             exporter->exportModuleHelp(*module->second, tag, displayName);
         }
     }
index e723e00b0e7b268f54f63f47cefd6b0e2b76a580..01d9fa7401cd23045722dbaede233a6edf66251c 100644 (file)
@@ -306,6 +306,8 @@ CommandLineModuleManager::Impl::Impl(const char                *binaryName,
       helpModule_(NULL), singleModule_(NULL),
       bQuiet_(false)
 {
+    GMX_RELEASE_ASSERT(binaryName_.find('-') == std::string::npos,
+                       "Help export does not currently work with binary names with dashes");
 }
 
 void CommandLineModuleManager::Impl::addModule(CommandLineModulePointer module)