#include <algorithm>
#include <string>
+#include <vector>
#include <boost/scoped_ptr.hpp>
#include "gromacs/commandline/cmdlinehelpcontext.h"
#include "gromacs/commandline/cmdlineparser.h"
+#include "gromacs/commandline/shellcompletions.h"
#include "gromacs/onlinehelp/helpformat.h"
#include "gromacs/onlinehelp/helpmanager.h"
#include "gromacs/onlinehelp/helptopic.h"
file->writeLine(footer_);
}
+/********************************************************************
+ * HelpExportCompletion
+ */
+
+/*! \internal \brief
+ * Implements export for command-line completion.
+ *
+ * \ingroup module_commandline
+ */
+class HelpExportCompletion : public HelpExportInterface
+{
+ public:
+ //! Initializes completion exporter.
+ explicit HelpExportCompletion(const CommandLineHelpModuleImpl &helpModule);
+
+ virtual void startModuleExport();
+ virtual void exportModuleHelp(
+ const CommandLineModuleInterface &module,
+ const std::string &tag,
+ const std::string &displayName);
+ virtual void finishModuleExport();
+
+ virtual void startModuleGroupExport() {}
+ virtual void exportModuleGroup(const char * /*title*/,
+ const ModuleGroupContents & /*modules*/) {}
+ virtual void finishModuleGroupExport() {}
+
+ private:
+ ShellCompletionWriter bashWriter_;
+ std::vector<std::string> modules_;
+};
+
+HelpExportCompletion::HelpExportCompletion(
+ const CommandLineHelpModuleImpl &helpModule)
+ : bashWriter_(helpModule.binaryName_, eShellCompletionFormat_Bash)
+{
+}
+
+void HelpExportCompletion::startModuleExport()
+{
+ bashWriter_.startCompletions();
+}
+
+void HelpExportCompletion::exportModuleHelp(
+ const CommandLineModuleInterface &module,
+ const std::string & /*tag*/,
+ const std::string & /*displayName*/)
+{
+ modules_.push_back(module.name());
+ {
+ CommandLineHelpContext context(&bashWriter_);
+ // We use the display name to pass the name of the module to the
+ // completion writer.
+ context.setModuleDisplayName(module.name());
+ module.writeHelp(context);
+ }
+}
+
+void HelpExportCompletion::finishModuleExport()
+{
+ bashWriter_.writeWrapperCompletions(modules_);
+ bashWriter_.finishCompletions();
+}
+
} // namespace
/********************************************************************
{
exporter.reset(new HelpExportHtml(*impl_));
}
+ else if (exportFormat == "completion")
+ {
+ exporter.reset(new HelpExportCompletion(*impl_));
+ }
else
{
GMX_THROW(NotImplementedError("This help format is not implemented"));