2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
37 * Implements gmx::CommandLineHelpModule.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \ingroup module_commandline
42 #include "gromacs/commandline/cmdlinehelpmodule.h"
48 #include <boost/scoped_ptr.hpp>
50 #include "gromacs/legacyheaders/copyrite.h"
52 #include "gromacs/commandline/cmdlinehelpcontext.h"
53 #include "gromacs/commandline/cmdlinehelpwriter.h"
54 #include "gromacs/commandline/cmdlineparser.h"
55 #include "gromacs/commandline/shellcompletions.h"
56 #include "gromacs/onlinehelp/helpformat.h"
57 #include "gromacs/onlinehelp/helpmanager.h"
58 #include "gromacs/onlinehelp/helptopic.h"
59 #include "gromacs/onlinehelp/helpwritercontext.h"
60 #include "gromacs/options/basicoptions.h"
61 #include "gromacs/options/options.h"
62 #include "gromacs/utility/exceptions.h"
63 #include "gromacs/utility/file.h"
64 #include "gromacs/utility/gmxassert.h"
65 #include "gromacs/utility/programcontext.h"
66 #include "gromacs/utility/stringutil.h"
73 class HelpExportInterface;
77 /********************************************************************
78 * CommandLineHelpModuleImpl declaration
81 class CommandLineHelpModuleImpl
84 CommandLineHelpModuleImpl(const ProgramContextInterface &programContext,
85 const std::string &binaryName,
86 const CommandLineModuleMap &modules,
87 const CommandLineModuleGroupList &groups);
89 void exportHelp(HelpExportInterface *exporter) const;
91 boost::scoped_ptr<RootHelpTopic> rootTopic_;
92 const ProgramContextInterface &programContext_;
93 std::string binaryName_;
94 const CommandLineModuleMap &modules_;
95 const CommandLineModuleGroupList &groups_;
97 CommandLineHelpContext *context_;
98 const CommandLineModuleInterface *moduleOverride_;
101 File *outputOverride_;
103 GMX_DISALLOW_COPY_AND_ASSIGN(CommandLineHelpModuleImpl);
109 /********************************************************************
115 static const char name[];
116 static const char title[];
117 static const char *const text[];
120 // The first two are not used.
121 const char RootHelpText::name[] = "";
122 const char RootHelpText::title[] = "";
123 const char *const RootHelpText::text[] = { "" };
126 * Help topic that forms the root of the help tree for the help subcommand.
128 * \ingroup module_commandline
130 class RootHelpTopic : public CompositeHelpTopic<RootHelpText>
134 * Creates a root help topic.
138 explicit RootHelpTopic(const std::string &binaryName)
139 : binaryName_(binaryName)
143 virtual void writeHelp(const HelpWriterContext &context) const;
146 std::string binaryName_;
148 GMX_DISALLOW_COPY_AND_ASSIGN(RootHelpTopic);
151 void RootHelpTopic::writeHelp(const HelpWriterContext &context) const
153 if (context.outputFormat() != eHelpOutputFormat_Console)
155 // TODO: Implement once the situation with Redmine issue #969 is more
157 GMX_THROW(NotImplementedError(
158 "Root help is not implemented for this output format"));
161 CommandLineCommonOptionsHolder optionsHolder;
162 CommandLineHelpContext cmdlineContext(context);
163 optionsHolder.initOptions();
164 cmdlineContext.setModuleDisplayName(binaryName_);
165 // TODO: Add <command> [<args>] into the synopsis.
166 // TODO: Propagate the -hidden option here.
167 CommandLineHelpWriter(*optionsHolder.options())
168 .writeHelp(cmdlineContext);
170 // TODO: Consider printing a list of "core" commands. Would require someone
171 // to determine such a set...
172 writeSubTopicList(context,
173 "Additional help is available on the following topics:");
174 context.writeTextBlock(
175 "To access the help, use '[PROGRAM] help <topic>'.[BR]"
176 "For help on a command, use '[PROGRAM] help <command>'.");
179 /********************************************************************
184 * Help topic for listing the commands.
186 * \ingroup module_commandline
188 class CommandsHelpTopic : public HelpTopicInterface
192 * Creates a command list help topic.
194 * \param[in] helpModule Help module to get module information from.
198 explicit CommandsHelpTopic(const CommandLineHelpModuleImpl &helpModule)
199 : helpModule_(helpModule)
203 virtual const char *name() const { return "commands"; }
204 virtual const char *title() const { return "List of available commands"; }
205 virtual bool hasSubTopics() const { return false; }
206 virtual const HelpTopicInterface *findSubTopic(const char * /*name*/) const
211 virtual void writeHelp(const HelpWriterContext &context) const;
214 const CommandLineHelpModuleImpl &helpModule_;
216 GMX_DISALLOW_COPY_AND_ASSIGN(CommandsHelpTopic);
219 void CommandsHelpTopic::writeHelp(const HelpWriterContext &context) const
221 if (context.outputFormat() != eHelpOutputFormat_Console)
223 GMX_THROW(NotImplementedError(
224 "Module list is not implemented for this output format"));
226 int maxNameLength = 0;
227 const CommandLineModuleMap &modules = helpModule_.modules_;
228 CommandLineModuleMap::const_iterator module;
229 for (module = modules.begin(); module != modules.end(); ++module)
231 int nameLength = static_cast<int>(module->first.length());
232 if (module->second->shortDescription() != NULL
233 && nameLength > maxNameLength)
235 maxNameLength = nameLength;
238 context.writeTextBlock(
239 "Usage: [PROGRAM] [<options>] <command> [<args>][PAR]"
240 "Available commands:");
241 File &file = context.outputFile();
242 TextTableFormatter formatter;
243 formatter.addColumn(NULL, maxNameLength + 1, false);
244 formatter.addColumn(NULL, 72 - maxNameLength, true);
245 formatter.setFirstColumnIndent(4);
246 for (module = modules.begin(); module != modules.end(); ++module)
248 const char *name = module->first.c_str();
249 const char *description = module->second->shortDescription();
250 if (description != NULL)
253 formatter.addColumnLine(0, name);
254 formatter.addColumnLine(1, description);
255 file.writeString(formatter.formatRow());
258 context.writeTextBlock(
259 "For help on a command, use '[PROGRAM] help <command>'.");
262 /********************************************************************
267 * Help topic wrapper for a command-line module.
269 * This class implements HelpTopicInterface such that it wraps a
270 * CommandLineModuleInterface, allowing subcommand "help <command>"
271 * to produce the help for "<command>".
273 * \ingroup module_commandline
275 class ModuleHelpTopic : public HelpTopicInterface
278 //! Constructs a help topic for a specific module.
279 ModuleHelpTopic(const CommandLineModuleInterface &module,
280 const CommandLineHelpModuleImpl &helpModule)
281 : module_(module), helpModule_(helpModule)
285 virtual const char *name() const { return module_.name(); }
286 virtual const char *title() const { return NULL; }
287 virtual bool hasSubTopics() const { return false; }
288 virtual const HelpTopicInterface *findSubTopic(const char * /*name*/) const
292 virtual void writeHelp(const HelpWriterContext &context) const;
295 const CommandLineModuleInterface &module_;
296 const CommandLineHelpModuleImpl &helpModule_;
298 GMX_DISALLOW_COPY_AND_ASSIGN(ModuleHelpTopic);
301 void ModuleHelpTopic::writeHelp(const HelpWriterContext & /*context*/) const
303 CommandLineHelpContext context(*helpModule_.context_);
304 const char *const program = helpModule_.binaryName_.c_str();
305 context.setModuleDisplayName(formatString("%s %s", program, module_.name()));
306 module_.writeHelp(context);
309 /********************************************************************
310 * HelpExportInterface
314 * Callbacks for exporting help information for command-line modules.
316 * \ingroup module_commandline
318 class HelpExportInterface
321 //! Shorthand for a list of modules contained in a group.
322 typedef CommandLineModuleGroupData::ModuleList ModuleGroupContents;
324 virtual ~HelpExportInterface() {};
327 * Called once before exporting individual modules.
329 * Can, e.g., open shared output files (e.g., if the output is written
330 * into a single file, or if a separate index is required) and write
333 virtual void startModuleExport() = 0;
335 * Called to export the help for each module.
337 * \param[in] module Module for which the help should be exported.
338 * \param[in] tag Unique tag for the module (gmx-something).
339 * \param[in] displayName Display name for the module (gmx something).
341 virtual void exportModuleHelp(
342 const CommandLineModuleInterface &module,
343 const std::string &tag,
344 const std::string &displayName) = 0;
346 * Called after all modules have been exported.
348 * Can close files opened in startModuleExport(), write footers to them
351 virtual void finishModuleExport() = 0;
354 * Called once before exporting module groups.
356 * Can, e.g., open a single output file for listing all the groups.
358 virtual void startModuleGroupExport() = 0;
360 * Called to export the help for each module group.
362 * \param[in] title Title for the group.
363 * \param[in] modules List of modules in the group.
365 virtual void exportModuleGroup(const char *title,
366 const ModuleGroupContents &modules) = 0;
368 * Called after all module groups have been exported.
370 * Can close files opened in startModuleGroupExport(), write footers to them
373 virtual void finishModuleGroupExport() = 0;
377 * Adds hyperlinks to modules within this binary.
379 * \param[in,out] links Links are added here.
380 * \param[in] helpModule Help module to get module information from.
381 * \throws std::bad_alloc if out of memory.
383 * Initializes a HelpLinks object with links to modules defined in
386 * \ingroup module_commandline
388 void initProgramLinks(HelpLinks *links, const CommandLineHelpModuleImpl &helpModule)
390 const char *const program = helpModule.binaryName_.c_str();
391 CommandLineModuleMap::const_iterator module;
392 for (module = helpModule.modules_.begin();
393 module != helpModule.modules_.end();
396 if (module->second->shortDescription() != NULL)
398 std::string linkName("[gmx-" + module->first + "]");
399 std::string targetName(
400 formatString("%s-%s", program, module->first.c_str()));
401 std::string displayName(
402 formatString("[TT]%s %s[tt]", program, module->first.c_str()));
403 links->addLink(linkName, targetName, displayName);
408 /********************************************************************
413 * Implements export for man pages.
415 * \ingroup module_commandline
417 class HelpExportMan : public HelpExportInterface
420 //! Initializes man page exporter.
421 explicit HelpExportMan(const CommandLineHelpModuleImpl &helpModule)
422 : links_(eHelpOutputFormat_Man)
424 initProgramLinks(&links_, helpModule);
427 virtual void startModuleExport() {}
428 virtual void exportModuleHelp(
429 const CommandLineModuleInterface &module,
430 const std::string &tag,
431 const std::string &displayName);
432 virtual void finishModuleExport() {}
434 virtual void startModuleGroupExport();
435 virtual void exportModuleGroup(const char *title,
436 const ModuleGroupContents &modules);
437 virtual void finishModuleGroupExport();
441 boost::scoped_ptr<File> man7File_;
442 std::string man7Footer_;
445 void HelpExportMan::exportModuleHelp(
446 const CommandLineModuleInterface &module,
447 const std::string &tag,
448 const std::string &displayName)
450 File file("man1/" + tag + ".1", "w");
452 // TODO: It would be nice to remove the VERSION prefix from the version
453 // string to make it shorter.
454 file.writeLine(formatString(".TH %s 1 \"\" \"%s\" \"GROMACS Manual\"\n",
457 file.writeLine(".SH NAME");
458 file.writeLine(formatString("%s - %s", tag.c_str(),
459 module.shortDescription()));
462 CommandLineHelpContext context(&file, eHelpOutputFormat_Man, &links_);
463 context.setModuleDisplayName(displayName);
464 module.writeHelp(context);
466 file.writeLine(".SH SEE ALSO");
467 file.writeLine(".BR gromacs(7)");
469 file.writeLine("More information about \\fBGROMACS\\fR is available at <\\fIhttp://www.gromacs.org/\\fR>.");
472 void HelpExportMan::startModuleGroupExport()
474 const char *const programListPlaceholder = "@PROGMANPAGES@";
476 const std::string man7Template = gmx::File::readToString("man7/gromacs.7.in");
477 const size_t index = man7Template.find(programListPlaceholder);
478 GMX_RELEASE_ASSERT(index != std::string::npos,
479 "gromacs.7.in must contain a @PROGMANPAGES@ line");
480 std::string header = man7Template.substr(0, index);
481 man7Footer_ = man7Template.substr(index + std::strlen(programListPlaceholder));
482 header = replaceAll(header, "@VERSION@", GromacsVersion());
483 man7File_.reset(new File("man7/gromacs.7", "w"));
484 man7File_->writeLine(header);
487 void HelpExportMan::exportModuleGroup(const char *title,
488 const ModuleGroupContents &modules)
490 man7File_->writeLine(formatString(".Sh \"%s\"", title));
491 man7File_->writeLine(formatString(".IX Subsection \"%s\"", title));
492 man7File_->writeLine(".Vb");
493 man7File_->writeLine(".ta 16n");
495 ModuleGroupContents::const_iterator module;
496 for (module = modules.begin(); module != modules.end(); ++module)
498 const std::string &tag(module->first);
499 man7File_->writeLine(formatString("\\& %s\t%s",
500 tag.c_str(), module->second));
503 man7File_->writeLine(".Ve");
506 void HelpExportMan::finishModuleGroupExport()
508 man7File_->writeLine(man7Footer_);
512 /********************************************************************
517 * Implements export for HTML help.
519 * \ingroup module_commandline
521 class HelpExportHtml : public HelpExportInterface
524 //! Initializes HTML exporter.
525 explicit HelpExportHtml(const CommandLineHelpModuleImpl &helpModule);
527 virtual void startModuleExport();
528 virtual void exportModuleHelp(
529 const CommandLineModuleInterface &module,
530 const std::string &tag,
531 const std::string &displayName);
532 virtual void finishModuleExport();
534 virtual void startModuleGroupExport();
535 virtual void exportModuleGroup(const char *title,
536 const ModuleGroupContents &modules);
537 virtual void finishModuleGroupExport();
540 void setupHeaderAndFooter();
542 void writeHtmlHeader(File *file, const std::string &title) const;
543 void writeHtmlFooter(File *file) const;
546 boost::scoped_ptr<File> indexFile_;
551 HelpExportHtml::HelpExportHtml(const CommandLineHelpModuleImpl &helpModule)
552 : links_(eHelpOutputFormat_Html)
554 initProgramLinks(&links_, helpModule);
555 File linksFile("links.dat", "r");
557 while (linksFile.readLine(&line))
559 links_.addLink(line, "../online/" + line, line);
562 setupHeaderAndFooter();
565 void HelpExportHtml::setupHeaderAndFooter()
567 header_ = gmx::File::readToString("header.html.in");
568 header_ = replaceAll(header_, "@VERSION@", GromacsVersion());
569 gmx::File::writeFileFromString("header.html", header_);
570 header_ = replaceAll(header_, "@ROOTPATH@", "../");
571 footer_ = gmx::File::readToString("footer.html");
574 void HelpExportHtml::startModuleExport()
576 indexFile_.reset(new File("final/programs/byname.html", "w"));
577 writeHtmlHeader(indexFile_.get(), "GROMACS Programs by Name");
578 indexFile_->writeLine("<H3>GROMACS Programs Alphabetically</H3>");
581 void HelpExportHtml::exportModuleHelp(
582 const CommandLineModuleInterface &module,
583 const std::string &tag,
584 const std::string &displayName)
586 File file("final/programs/" + tag + ".html", "w");
587 writeHtmlHeader(&file, displayName);
589 CommandLineHelpContext context(&file, eHelpOutputFormat_Html, &links_);
590 context.setModuleDisplayName(displayName);
591 module.writeHelp(context);
593 writeHtmlFooter(&file);
596 indexFile_->writeLine(formatString("<a href=\"%s.html\">%s</a> - %s<br>",
597 tag.c_str(), displayName.c_str(),
598 module.shortDescription()));
601 void HelpExportHtml::finishModuleExport()
603 writeHtmlFooter(indexFile_.get());
607 void HelpExportHtml::startModuleGroupExport()
609 indexFile_.reset(new File("final/programs/bytopic.html", "w"));
610 writeHtmlHeader(indexFile_.get(), "GROMACS Programs by Topic");
611 indexFile_->writeLine("<H3>GROMACS Programs by Topic</H3>");
614 void HelpExportHtml::exportModuleGroup(const char *title,
615 const ModuleGroupContents &modules)
617 indexFile_->writeLine(formatString("<H4>%s</H4>", title));
619 ModuleGroupContents::const_iterator module;
620 for (module = modules.begin(); module != modules.end(); ++module)
622 const std::string &tag(module->first);
623 std::string displayName(tag);
624 std::replace(displayName.begin(), displayName.end(), '-', ' ');
625 indexFile_->writeLine(formatString("<a href=\"%s.html\">%s</a> - %s<br>",
626 tag.c_str(), displayName.c_str(),
631 void HelpExportHtml::finishModuleGroupExport()
633 writeHtmlFooter(indexFile_.get());
637 void HelpExportHtml::writeHtmlHeader(File *file, const std::string &title) const
639 file->writeLine(replaceAll(header_, "@TITLE@", title));
642 void HelpExportHtml::writeHtmlFooter(File *file) const
644 file->writeLine(footer_);
647 /********************************************************************
648 * HelpExportCompletion
652 * Implements export for command-line completion.
654 * \ingroup module_commandline
656 class HelpExportCompletion : public HelpExportInterface
659 //! Initializes completion exporter.
660 explicit HelpExportCompletion(const CommandLineHelpModuleImpl &helpModule);
662 virtual void startModuleExport();
663 virtual void exportModuleHelp(
664 const CommandLineModuleInterface &module,
665 const std::string &tag,
666 const std::string &displayName);
667 virtual void finishModuleExport();
669 virtual void startModuleGroupExport() {}
670 virtual void exportModuleGroup(const char * /*title*/,
671 const ModuleGroupContents & /*modules*/) {}
672 virtual void finishModuleGroupExport() {}
675 ShellCompletionWriter bashWriter_;
676 std::vector<std::string> modules_;
679 HelpExportCompletion::HelpExportCompletion(
680 const CommandLineHelpModuleImpl &helpModule)
681 : bashWriter_(helpModule.binaryName_, eShellCompletionFormat_Bash)
685 void HelpExportCompletion::startModuleExport()
687 bashWriter_.startCompletions();
690 void HelpExportCompletion::exportModuleHelp(
691 const CommandLineModuleInterface &module,
692 const std::string & /*tag*/,
693 const std::string & /*displayName*/)
695 modules_.push_back(module.name());
697 CommandLineHelpContext context(&bashWriter_);
698 // We use the display name to pass the name of the module to the
699 // completion writer.
700 context.setModuleDisplayName(module.name());
701 module.writeHelp(context);
705 void HelpExportCompletion::finishModuleExport()
707 CommandLineCommonOptionsHolder optionsHolder;
708 optionsHolder.initOptions();
709 bashWriter_.writeWrapperCompletions(modules_, *optionsHolder.options());
710 bashWriter_.finishCompletions();
715 /********************************************************************
716 * CommandLineHelpModuleImpl implementation
718 CommandLineHelpModuleImpl::CommandLineHelpModuleImpl(
719 const ProgramContextInterface &programContext,
720 const std::string &binaryName,
721 const CommandLineModuleMap &modules,
722 const CommandLineModuleGroupList &groups)
723 : rootTopic_(new RootHelpTopic(binaryName)), programContext_(programContext),
724 binaryName_(binaryName), modules_(modules), groups_(groups),
725 context_(NULL), moduleOverride_(NULL), bHidden_(false),
726 outputOverride_(NULL)
730 void CommandLineHelpModuleImpl::exportHelp(HelpExportInterface *exporter) const
732 // TODO: Would be nicer to have the file names supplied by the build system
733 // and/or export a list of files from here.
734 const char *const program = binaryName_.c_str();
736 exporter->startModuleExport();
737 CommandLineModuleMap::const_iterator module;
738 for (module = modules_.begin(); module != modules_.end(); ++module)
740 if (module->second->shortDescription() != NULL)
742 const char *const moduleName = module->first.c_str();
743 std::string tag(formatString("%s-%s", program, moduleName));
744 std::string displayName(tag);
745 std::replace(displayName.begin(), displayName.end(), '-', ' ');
746 exporter->exportModuleHelp(*module->second, tag, displayName);
749 exporter->finishModuleExport();
751 exporter->startModuleGroupExport();
752 CommandLineModuleGroupList::const_iterator group;
753 for (group = groups_.begin(); group != groups_.end(); ++group)
755 exporter->exportModuleGroup((*group)->title(), (*group)->modules());
757 exporter->finishModuleGroupExport();
760 /********************************************************************
761 * CommandLineHelpModule
764 CommandLineHelpModule::CommandLineHelpModule(
765 const ProgramContextInterface &programContext,
766 const std::string &binaryName,
767 const CommandLineModuleMap &modules,
768 const CommandLineModuleGroupList &groups)
769 : impl_(new Impl(programContext, binaryName, modules, groups))
773 CommandLineHelpModule::~CommandLineHelpModule()
777 HelpTopicPointer CommandLineHelpModule::createModuleHelpTopic(
778 const CommandLineModuleInterface &module) const
780 return HelpTopicPointer(new ModuleHelpTopic(module, *impl_));
783 void CommandLineHelpModule::addTopic(HelpTopicPointer topic)
785 impl_->rootTopic_->addSubTopic(move(topic));
788 void CommandLineHelpModule::setShowHidden(bool bHidden)
790 impl_->bHidden_ = bHidden;
793 void CommandLineHelpModule::setModuleOverride(
794 const CommandLineModuleInterface &module)
796 impl_->moduleOverride_ = &module;
799 void CommandLineHelpModule::setOutputRedirect(File *output)
801 impl_->outputOverride_ = output;
804 int CommandLineHelpModule::run(int argc, char *argv[])
806 // Add internal topics lazily here.
807 addTopic(HelpTopicPointer(new CommandsHelpTopic(*impl_)));
809 const char *const exportFormats[] = { "man", "html", "completion" };
810 std::string exportFormat;
811 Options options(NULL, NULL);
812 options.addOption(StringOption("export").store(&exportFormat)
813 .enumValue(exportFormats));
814 CommandLineParser(&options).parse(&argc, argv);
815 if (!exportFormat.empty())
817 boost::scoped_ptr<HelpExportInterface> exporter;
818 if (exportFormat == "man")
820 exporter.reset(new HelpExportMan(*impl_));
822 else if (exportFormat == "html")
824 exporter.reset(new HelpExportHtml(*impl_));
826 else if (exportFormat == "completion")
828 exporter.reset(new HelpExportCompletion(*impl_));
832 GMX_THROW(NotImplementedError("This help format is not implemented"));
834 impl_->exportHelp(exporter.get());
838 File *outputFile = &File::standardOutput();
839 if (impl_->outputOverride_ != NULL)
841 outputFile = impl_->outputOverride_;
843 HelpLinks links(eHelpOutputFormat_Console);
844 initProgramLinks(&links, *impl_);
845 boost::scoped_ptr<CommandLineHelpContext> context(
846 new CommandLineHelpContext(outputFile,
847 eHelpOutputFormat_Console, &links));
848 context->setShowHidden(impl_->bHidden_);
849 if (impl_->moduleOverride_ != NULL)
851 context->setModuleDisplayName(impl_->programContext_.displayName());
852 impl_->moduleOverride_->writeHelp(*context);
855 impl_->context_ = context.get();
857 HelpManager helpManager(*impl_->rootTopic_, context->writerContext());
860 for (int i = 1; i < argc; ++i)
862 helpManager.enterTopic(argv[i]);
865 catch (const InvalidInputError &ex)
867 fprintf(stderr, "%s\n", ex.what());
870 helpManager.writeCurrentTopic();
874 void CommandLineHelpModule::writeHelp(const CommandLineHelpContext &context) const
876 const HelpWriterContext &writerContext = context.writerContext();
878 if (writerContext.outputFormat() != eHelpOutputFormat_Console)
882 writerContext.writeTextBlock(
883 "Usage: [PROGRAM] help [<command>|<topic> [<subtopic> [...]]]");
884 // TODO: More information.