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), commonOptions_(NULL)
143 //! Sets the common options for the wrapper binary.
144 void setCommonOptions(const Options *options)
146 commonOptions_ = options;
149 virtual void writeHelp(const HelpWriterContext &context) const;
152 std::string binaryName_;
153 const Options *commonOptions_;
155 GMX_DISALLOW_COPY_AND_ASSIGN(RootHelpTopic);
158 void RootHelpTopic::writeHelp(const HelpWriterContext &context) const
160 if (context.outputFormat() != eHelpOutputFormat_Console)
162 // TODO: Implement once the situation with Redmine issue #969 is more
164 GMX_THROW(NotImplementedError(
165 "Root help is not implemented for this output format"));
168 CommandLineHelpContext cmdlineContext(context);
169 cmdlineContext.setModuleDisplayName(binaryName_);
170 // TODO: Add <command> [<args>] into the synopsis.
171 // TODO: Propagate the -hidden option here.
172 CommandLineHelpWriter(*commonOptions_)
173 .writeHelp(cmdlineContext);
175 // TODO: Consider printing a list of "core" commands. Would require someone
176 // to determine such a set...
177 writeSubTopicList(context,
178 "Additional help is available on the following topics:");
179 context.writeTextBlock(
180 "To access the help, use '[PROGRAM] help <topic>'.[BR]"
181 "For help on a command, use '[PROGRAM] help <command>'.");
184 /********************************************************************
189 * Help topic for listing the commands.
191 * \ingroup module_commandline
193 class CommandsHelpTopic : public HelpTopicInterface
197 * Creates a command list help topic.
199 * \param[in] helpModule Help module to get module information from.
203 explicit CommandsHelpTopic(const CommandLineHelpModuleImpl &helpModule)
204 : helpModule_(helpModule)
208 virtual const char *name() const { return "commands"; }
209 virtual const char *title() const { return "List of available commands"; }
210 virtual bool hasSubTopics() const { return false; }
211 virtual const HelpTopicInterface *findSubTopic(const char * /*name*/) const
216 virtual void writeHelp(const HelpWriterContext &context) const;
219 const CommandLineHelpModuleImpl &helpModule_;
221 GMX_DISALLOW_COPY_AND_ASSIGN(CommandsHelpTopic);
224 void CommandsHelpTopic::writeHelp(const HelpWriterContext &context) const
226 if (context.outputFormat() != eHelpOutputFormat_Console)
228 GMX_THROW(NotImplementedError(
229 "Module list is not implemented for this output format"));
231 int maxNameLength = 0;
232 const CommandLineModuleMap &modules = helpModule_.modules_;
233 CommandLineModuleMap::const_iterator module;
234 for (module = modules.begin(); module != modules.end(); ++module)
236 int nameLength = static_cast<int>(module->first.length());
237 if (module->second->shortDescription() != NULL
238 && nameLength > maxNameLength)
240 maxNameLength = nameLength;
243 context.writeTextBlock(
244 "Usage: [PROGRAM] [<options>] <command> [<args>][PAR]"
245 "Available commands:");
246 File &file = context.outputFile();
247 TextTableFormatter formatter;
248 formatter.addColumn(NULL, maxNameLength + 1, false);
249 formatter.addColumn(NULL, 72 - maxNameLength, true);
250 formatter.setFirstColumnIndent(4);
251 for (module = modules.begin(); module != modules.end(); ++module)
253 const char *name = module->first.c_str();
254 const char *description = module->second->shortDescription();
255 if (description != NULL)
258 formatter.addColumnLine(0, name);
259 formatter.addColumnLine(1, description);
260 file.writeString(formatter.formatRow());
263 context.writeTextBlock(
264 "For help on a command, use '[PROGRAM] help <command>'.");
267 /********************************************************************
272 * Help topic wrapper for a command-line module.
274 * This class implements HelpTopicInterface such that it wraps a
275 * CommandLineModuleInterface, allowing subcommand "help <command>"
276 * to produce the help for "<command>".
278 * \ingroup module_commandline
280 class ModuleHelpTopic : public HelpTopicInterface
283 //! Constructs a help topic for a specific module.
284 ModuleHelpTopic(const CommandLineModuleInterface &module,
285 const CommandLineHelpModuleImpl &helpModule)
286 : module_(module), helpModule_(helpModule)
290 virtual const char *name() const { return module_.name(); }
291 virtual const char *title() const { return NULL; }
292 virtual bool hasSubTopics() const { return false; }
293 virtual const HelpTopicInterface *findSubTopic(const char * /*name*/) const
297 virtual void writeHelp(const HelpWriterContext &context) const;
300 const CommandLineModuleInterface &module_;
301 const CommandLineHelpModuleImpl &helpModule_;
303 GMX_DISALLOW_COPY_AND_ASSIGN(ModuleHelpTopic);
306 void ModuleHelpTopic::writeHelp(const HelpWriterContext & /*context*/) const
308 CommandLineHelpContext context(*helpModule_.context_);
309 const char *const program = helpModule_.binaryName_.c_str();
310 context.setModuleDisplayName(formatString("%s %s", program, module_.name()));
311 module_.writeHelp(context);
314 /********************************************************************
315 * HelpExportInterface
319 * Callbacks for exporting help information for command-line modules.
321 * \ingroup module_commandline
323 class HelpExportInterface
326 //! Shorthand for a list of modules contained in a group.
327 typedef CommandLineModuleGroupData::ModuleList ModuleGroupContents;
329 virtual ~HelpExportInterface() {};
332 * Called once before exporting individual modules.
334 * Can, e.g., open shared output files (e.g., if the output is written
335 * into a single file, or if a separate index is required) and write
338 virtual void startModuleExport() = 0;
340 * Called to export the help for each module.
342 * \param[in] module Module for which the help should be exported.
343 * \param[in] tag Unique tag for the module (gmx-something).
344 * \param[in] displayName Display name for the module (gmx something).
346 virtual void exportModuleHelp(
347 const CommandLineModuleInterface &module,
348 const std::string &tag,
349 const std::string &displayName) = 0;
351 * Called after all modules have been exported.
353 * Can close files opened in startModuleExport(), write footers to them
356 virtual void finishModuleExport() = 0;
359 * Called once before exporting module groups.
361 * Can, e.g., open a single output file for listing all the groups.
363 virtual void startModuleGroupExport() = 0;
365 * Called to export the help for each module group.
367 * \param[in] title Title for the group.
368 * \param[in] modules List of modules in the group.
370 virtual void exportModuleGroup(const char *title,
371 const ModuleGroupContents &modules) = 0;
373 * Called after all module groups have been exported.
375 * Can close files opened in startModuleGroupExport(), write footers to them
378 virtual void finishModuleGroupExport() = 0;
382 * Adds hyperlinks to modules within this binary.
384 * \param[in,out] links Links are added here.
385 * \param[in] helpModule Help module to get module information from.
386 * \throws std::bad_alloc if out of memory.
388 * Initializes a HelpLinks object with links to modules defined in
391 * \ingroup module_commandline
393 void initProgramLinks(HelpLinks *links, const CommandLineHelpModuleImpl &helpModule)
395 const char *const program = helpModule.binaryName_.c_str();
396 CommandLineModuleMap::const_iterator module;
397 for (module = helpModule.modules_.begin();
398 module != helpModule.modules_.end();
401 if (module->second->shortDescription() != NULL)
403 std::string linkName("[gmx-" + module->first + "]");
404 std::string targetName(
405 formatString("%s-%s", program, module->first.c_str()));
406 std::string displayName(
407 formatString("[TT]%s %s[tt]", program, module->first.c_str()));
408 links->addLink(linkName, targetName, displayName);
413 /********************************************************************
418 * Implements export for man pages.
420 * \ingroup module_commandline
422 class HelpExportMan : public HelpExportInterface
425 //! Initializes man page exporter.
426 explicit HelpExportMan(const CommandLineHelpModuleImpl &helpModule)
427 : links_(eHelpOutputFormat_Man)
429 initProgramLinks(&links_, helpModule);
432 virtual void startModuleExport() {}
433 virtual void exportModuleHelp(
434 const CommandLineModuleInterface &module,
435 const std::string &tag,
436 const std::string &displayName);
437 virtual void finishModuleExport() {}
439 virtual void startModuleGroupExport();
440 virtual void exportModuleGroup(const char *title,
441 const ModuleGroupContents &modules);
442 virtual void finishModuleGroupExport();
446 boost::scoped_ptr<File> man7File_;
447 std::string man7Footer_;
450 void HelpExportMan::exportModuleHelp(
451 const CommandLineModuleInterface &module,
452 const std::string &tag,
453 const std::string &displayName)
455 File file("man1/" + tag + ".1", "w");
457 // TODO: It would be nice to remove the VERSION prefix from the version
458 // string to make it shorter.
459 file.writeLine(formatString(".TH %s 1 \"\" \"%s\" \"GROMACS Manual\"\n",
462 file.writeLine(".SH NAME");
463 file.writeLine(formatString("%s - %s", tag.c_str(),
464 module.shortDescription()));
467 CommandLineHelpContext context(&file, eHelpOutputFormat_Man, &links_);
468 context.setModuleDisplayName(displayName);
469 module.writeHelp(context);
471 file.writeLine(".SH SEE ALSO");
472 file.writeLine(".BR gromacs(7)");
474 file.writeLine("More information about \\fBGROMACS\\fR is available at <\\fIhttp://www.gromacs.org/\\fR>.");
477 void HelpExportMan::startModuleGroupExport()
479 const char *const programListPlaceholder = "@PROGMANPAGES@";
481 const std::string man7Template = gmx::File::readToString("man7/gromacs.7.in");
482 const size_t index = man7Template.find(programListPlaceholder);
483 GMX_RELEASE_ASSERT(index != std::string::npos,
484 "gromacs.7.in must contain a @PROGMANPAGES@ line");
485 std::string header = man7Template.substr(0, index);
486 man7Footer_ = man7Template.substr(index + std::strlen(programListPlaceholder));
487 header = replaceAll(header, "@VERSION@", GromacsVersion());
488 man7File_.reset(new File("man7/gromacs.7", "w"));
489 man7File_->writeLine(header);
492 void HelpExportMan::exportModuleGroup(const char *title,
493 const ModuleGroupContents &modules)
495 man7File_->writeLine(formatString(".Sh \"%s\"", title));
496 man7File_->writeLine(formatString(".IX Subsection \"%s\"", title));
497 man7File_->writeLine(".Vb");
498 man7File_->writeLine(".ta 16n");
500 ModuleGroupContents::const_iterator module;
501 for (module = modules.begin(); module != modules.end(); ++module)
503 const std::string &tag(module->first);
504 man7File_->writeLine(formatString("\\& %s\t%s",
505 tag.c_str(), module->second));
508 man7File_->writeLine(".Ve");
511 void HelpExportMan::finishModuleGroupExport()
513 man7File_->writeLine(man7Footer_);
517 /********************************************************************
522 * Implements export for HTML help.
524 * \ingroup module_commandline
526 class HelpExportHtml : public HelpExportInterface
529 //! Initializes HTML exporter.
530 explicit HelpExportHtml(const CommandLineHelpModuleImpl &helpModule);
532 virtual void startModuleExport();
533 virtual void exportModuleHelp(
534 const CommandLineModuleInterface &module,
535 const std::string &tag,
536 const std::string &displayName);
537 virtual void finishModuleExport();
539 virtual void startModuleGroupExport();
540 virtual void exportModuleGroup(const char *title,
541 const ModuleGroupContents &modules);
542 virtual void finishModuleGroupExport();
545 void setupHeaderAndFooter();
547 void writeHtmlHeader(File *file, const std::string &title) const;
548 void writeHtmlFooter(File *file) const;
551 boost::scoped_ptr<File> indexFile_;
556 HelpExportHtml::HelpExportHtml(const CommandLineHelpModuleImpl &helpModule)
557 : links_(eHelpOutputFormat_Html)
559 initProgramLinks(&links_, helpModule);
560 File linksFile("links.dat", "r");
562 while (linksFile.readLine(&line))
564 links_.addLink(line, "../online/" + line, line);
567 setupHeaderAndFooter();
570 void HelpExportHtml::setupHeaderAndFooter()
572 header_ = gmx::File::readToString("header.html.in");
573 header_ = replaceAll(header_, "@VERSION@", GromacsVersion());
574 gmx::File::writeFileFromString("header.html", header_);
575 header_ = replaceAll(header_, "@ROOTPATH@", "../");
576 footer_ = gmx::File::readToString("footer.html");
579 void HelpExportHtml::startModuleExport()
581 indexFile_.reset(new File("final/programs/byname.html", "w"));
582 writeHtmlHeader(indexFile_.get(), "GROMACS Programs by Name");
583 indexFile_->writeLine("<H3>GROMACS Programs Alphabetically</H3>");
586 void HelpExportHtml::exportModuleHelp(
587 const CommandLineModuleInterface &module,
588 const std::string &tag,
589 const std::string &displayName)
591 File file("final/programs/" + tag + ".html", "w");
592 writeHtmlHeader(&file, displayName);
594 CommandLineHelpContext context(&file, eHelpOutputFormat_Html, &links_);
595 context.setModuleDisplayName(displayName);
596 module.writeHelp(context);
598 writeHtmlFooter(&file);
601 indexFile_->writeLine(formatString("<a href=\"%s.html\">%s</a> - %s<br>",
602 tag.c_str(), displayName.c_str(),
603 module.shortDescription()));
606 void HelpExportHtml::finishModuleExport()
608 writeHtmlFooter(indexFile_.get());
612 void HelpExportHtml::startModuleGroupExport()
614 indexFile_.reset(new File("final/programs/bytopic.html", "w"));
615 writeHtmlHeader(indexFile_.get(), "GROMACS Programs by Topic");
616 indexFile_->writeLine("<H3>GROMACS Programs by Topic</H3>");
619 void HelpExportHtml::exportModuleGroup(const char *title,
620 const ModuleGroupContents &modules)
622 indexFile_->writeLine(formatString("<H4>%s</H4>", title));
624 ModuleGroupContents::const_iterator module;
625 for (module = modules.begin(); module != modules.end(); ++module)
627 const std::string &tag(module->first);
628 std::string displayName(tag);
629 std::replace(displayName.begin(), displayName.end(), '-', ' ');
630 indexFile_->writeLine(formatString("<a href=\"%s.html\">%s</a> - %s<br>",
631 tag.c_str(), displayName.c_str(),
636 void HelpExportHtml::finishModuleGroupExport()
638 writeHtmlFooter(indexFile_.get());
642 void HelpExportHtml::writeHtmlHeader(File *file, const std::string &title) const
644 file->writeLine(replaceAll(header_, "@TITLE@", title));
647 void HelpExportHtml::writeHtmlFooter(File *file) const
649 file->writeLine(footer_);
652 /********************************************************************
653 * HelpExportCompletion
657 * Implements export for command-line completion.
659 * \ingroup module_commandline
661 class HelpExportCompletion : public HelpExportInterface
664 //! Initializes completion exporter.
665 explicit HelpExportCompletion(const CommandLineHelpModuleImpl &helpModule);
667 virtual void startModuleExport();
668 virtual void exportModuleHelp(
669 const CommandLineModuleInterface &module,
670 const std::string &tag,
671 const std::string &displayName);
672 virtual void finishModuleExport();
674 virtual void startModuleGroupExport() {}
675 virtual void exportModuleGroup(const char * /*title*/,
676 const ModuleGroupContents & /*modules*/) {}
677 virtual void finishModuleGroupExport() {}
680 ShellCompletionWriter bashWriter_;
681 std::vector<std::string> modules_;
684 HelpExportCompletion::HelpExportCompletion(
685 const CommandLineHelpModuleImpl &helpModule)
686 : bashWriter_(helpModule.binaryName_, eShellCompletionFormat_Bash)
690 void HelpExportCompletion::startModuleExport()
692 bashWriter_.startCompletions();
695 void HelpExportCompletion::exportModuleHelp(
696 const CommandLineModuleInterface &module,
697 const std::string & /*tag*/,
698 const std::string & /*displayName*/)
700 modules_.push_back(module.name());
702 CommandLineHelpContext context(&bashWriter_);
703 // We use the display name to pass the name of the module to the
704 // completion writer.
705 context.setModuleDisplayName(module.name());
706 module.writeHelp(context);
710 void HelpExportCompletion::finishModuleExport()
712 bashWriter_.writeWrapperCompletions(modules_);
713 bashWriter_.finishCompletions();
718 /********************************************************************
719 * CommandLineHelpModuleImpl implementation
721 CommandLineHelpModuleImpl::CommandLineHelpModuleImpl(
722 const ProgramContextInterface &programContext,
723 const std::string &binaryName,
724 const CommandLineModuleMap &modules,
725 const CommandLineModuleGroupList &groups)
726 : rootTopic_(new RootHelpTopic(binaryName)), programContext_(programContext),
727 binaryName_(binaryName), modules_(modules), groups_(groups),
728 context_(NULL), moduleOverride_(NULL), bHidden_(false),
729 outputOverride_(NULL)
733 void CommandLineHelpModuleImpl::exportHelp(HelpExportInterface *exporter) const
735 // TODO: Would be nicer to have the file names supplied by the build system
736 // and/or export a list of files from here.
737 const char *const program = binaryName_.c_str();
739 exporter->startModuleExport();
740 CommandLineModuleMap::const_iterator module;
741 for (module = modules_.begin(); module != modules_.end(); ++module)
743 if (module->second->shortDescription() != NULL)
745 const char *const moduleName = module->first.c_str();
746 std::string tag(formatString("%s-%s", program, moduleName));
747 std::string displayName(tag);
748 std::replace(displayName.begin(), displayName.end(), '-', ' ');
749 exporter->exportModuleHelp(*module->second, tag, displayName);
752 exporter->finishModuleExport();
754 exporter->startModuleGroupExport();
755 CommandLineModuleGroupList::const_iterator group;
756 for (group = groups_.begin(); group != groups_.end(); ++group)
758 exporter->exportModuleGroup((*group)->title(), (*group)->modules());
760 exporter->finishModuleGroupExport();
763 /********************************************************************
764 * CommandLineHelpModule
767 CommandLineHelpModule::CommandLineHelpModule(
768 const ProgramContextInterface &programContext,
769 const std::string &binaryName,
770 const CommandLineModuleMap &modules,
771 const CommandLineModuleGroupList &groups)
772 : impl_(new Impl(programContext, binaryName, modules, groups))
776 CommandLineHelpModule::~CommandLineHelpModule()
780 HelpTopicPointer CommandLineHelpModule::createModuleHelpTopic(
781 const CommandLineModuleInterface &module) const
783 return HelpTopicPointer(new ModuleHelpTopic(module, *impl_));
786 void CommandLineHelpModule::addTopic(HelpTopicPointer topic)
788 impl_->rootTopic_->addSubTopic(move(topic));
791 void CommandLineHelpModule::setShowHidden(bool bHidden)
793 impl_->bHidden_ = bHidden;
796 void CommandLineHelpModule::setCommonOptions(const Options *options)
798 impl_->rootTopic_->setCommonOptions(options);
801 void CommandLineHelpModule::setModuleOverride(
802 const CommandLineModuleInterface &module)
804 impl_->moduleOverride_ = &module;
807 void CommandLineHelpModule::setOutputRedirect(File *output)
809 impl_->outputOverride_ = output;
812 int CommandLineHelpModule::run(int argc, char *argv[])
814 // Add internal topics lazily here.
815 addTopic(HelpTopicPointer(new CommandsHelpTopic(*impl_)));
817 const char *const exportFormats[] = { "man", "html", "completion" };
818 std::string exportFormat;
819 Options options(NULL, NULL);
820 options.addOption(StringOption("export").store(&exportFormat)
821 .enumValue(exportFormats));
822 CommandLineParser(&options).parse(&argc, argv);
823 if (!exportFormat.empty())
825 boost::scoped_ptr<HelpExportInterface> exporter;
826 if (exportFormat == "man")
828 exporter.reset(new HelpExportMan(*impl_));
830 else if (exportFormat == "html")
832 exporter.reset(new HelpExportHtml(*impl_));
834 else if (exportFormat == "completion")
836 exporter.reset(new HelpExportCompletion(*impl_));
840 GMX_THROW(NotImplementedError("This help format is not implemented"));
842 impl_->exportHelp(exporter.get());
846 File *outputFile = &File::standardOutput();
847 if (impl_->outputOverride_ != NULL)
849 outputFile = impl_->outputOverride_;
851 HelpLinks links(eHelpOutputFormat_Console);
852 initProgramLinks(&links, *impl_);
853 boost::scoped_ptr<CommandLineHelpContext> context(
854 new CommandLineHelpContext(outputFile,
855 eHelpOutputFormat_Console, &links));
856 context->setShowHidden(impl_->bHidden_);
857 if (impl_->moduleOverride_ != NULL)
859 context->setModuleDisplayName(impl_->programContext_.displayName());
860 impl_->moduleOverride_->writeHelp(*context);
863 impl_->context_ = context.get();
865 HelpManager helpManager(*impl_->rootTopic_, context->writerContext());
868 for (int i = 1; i < argc; ++i)
870 helpManager.enterTopic(argv[i]);
873 catch (const InvalidInputError &ex)
875 fprintf(stderr, "%s\n", ex.what());
878 helpManager.writeCurrentTopic();
882 void CommandLineHelpModule::writeHelp(const CommandLineHelpContext &context) const
884 const HelpWriterContext &writerContext = context.writerContext();
886 if (writerContext.outputFormat() != eHelpOutputFormat_Console)
890 writerContext.writeTextBlock(
891 "Usage: [PROGRAM] help [<command>|<topic> [<subtopic> [...]]]");
892 // TODO: More information.