// The first two are not used.
const char RootHelpText::name[] = "";
const char RootHelpText::title[] = "";
-const char *const RootHelpText::text[] = {
- "Usage: [PROGRAM] [<options>] <command> [<args>]",
-};
+const char *const RootHelpText::text[] = { "" };
/*! \brief
* Help topic that forms the root of the help tree for the help subcommand.
*
* Does not throw.
*/
- RootHelpTopic() : commonOptions_(NULL)
+ explicit RootHelpTopic(const std::string &binaryName)
+ : binaryName_(binaryName), commonOptions_(NULL)
{
}
virtual void writeHelp(const HelpWriterContext &context) const;
private:
+ std::string binaryName_;
const Options *commonOptions_;
GMX_DISALLOW_COPY_AND_ASSIGN(RootHelpTopic);
GMX_THROW(NotImplementedError(
"Root help is not implemented for this output format"));
}
- writeBasicHelpTopic(context, *this, helpText());
- context.outputFile().writeLine();
{
CommandLineHelpContext cmdlineContext(context);
+ cmdlineContext.setModuleDisplayName(binaryName_);
+ // TODO: Add <command> [<args>] into the synopsis.
// TODO: Propagate the -hidden option here.
CommandLineHelpWriter(*commonOptions_)
.writeHelp(cmdlineContext);
const std::string &binaryName,
const CommandLineModuleMap &modules,
const CommandLineModuleGroupList &groups)
- : rootTopic_(new RootHelpTopic), programContext_(programContext),
+ : rootTopic_(new RootHelpTopic(binaryName)), programContext_(programContext),
binaryName_(binaryName), modules_(modules), groups_(groups),
context_(NULL), moduleOverride_(NULL), bHidden_(false),
outputOverride_(NULL)
*/
#include "cmdlinehelpwriter.h"
+#include <cstring>
+
+#include <algorithm>
#include <string>
#include <boost/scoped_ptr.hpp>
return description;
}
+/********************************************************************
+ * OptionsSynopsisFormatter
+ */
+
+/*! \brief
+ * Formatter implementation for synopsis.
+ */
+class SynopsisFormatter : public OptionsFormatterInterface
+{
+ public:
+ //! Creates a helper object for formatting the synopsis.
+ explicit SynopsisFormatter(const HelpWriterContext &context)
+ : context_(context), lineLength_(0), indent_(0), currentLength_(0)
+ {
+ }
+
+ //! Starts formatting the synopsis.
+ void start(const char *name);
+ //! Finishes formatting the synopsis.
+ void finish();
+
+ virtual void formatOption(const OptionInfo &option);
+
+ private:
+ const HelpWriterContext &context_;
+ int lineLength_;
+ int indent_;
+ int currentLength_;
+
+ GMX_DISALLOW_COPY_AND_ASSIGN(SynopsisFormatter);
+};
+
+void SynopsisFormatter::start(const char *name)
+{
+ currentLength_ = std::strlen(name) + 1;
+ indent_ = std::min(currentLength_, 13);
+ File &file = context_.outputFile();
+ switch (context_.outputFormat())
+ {
+ case eHelpOutputFormat_Console:
+ lineLength_ = 78;
+ file.writeString(name);
+ break;
+ case eHelpOutputFormat_Man:
+ lineLength_ = 70;
+ file.writeString(name);
+ break;
+ case eHelpOutputFormat_Html:
+ lineLength_ = 78;
+ file.writeLine("<pre>");
+ file.writeString(name);
+ break;
+ default:
+ GMX_THROW(NotImplementedError("Synopsis formatting not implemented for this output format"));
+ }
+}
+
+void SynopsisFormatter::finish()
+{
+ File &file = context_.outputFile();
+ file.writeLine();
+ if (context_.outputFormat() == eHelpOutputFormat_Html)
+ {
+ file.writeLine("</pre>");
+ }
+ file.writeLine();
+}
+
+void SynopsisFormatter::formatOption(const OptionInfo &option)
+{
+ std::string name, value;
+ formatOptionNameAndValue(option, &name, &value);
+ std::string fullOptionText(" [-" + name);
+ if (!value.empty())
+ {
+ fullOptionText.append(" ");
+ fullOptionText.append(value);
+ }
+ fullOptionText.append("]");
+ const int totalLength = fullOptionText.size();
+
+ if (context_.outputFormat() == eHelpOutputFormat_Html)
+ {
+ value = replaceAll(value, "<", "<");
+ value = replaceAll(value, ">", ">");
+ }
+
+ File &file = context_.outputFile();
+ currentLength_ += totalLength;
+ if (currentLength_ >= lineLength_)
+ {
+ file.writeString(formatString("\n%*c", indent_ - 1, ' '));
+ currentLength_ = indent_ - 1 + totalLength;
+ }
+ file.writeString(fullOptionText);
+}
+
/********************************************************************
* OptionsListFormatter
*/
OptionsFilter filter;
filter.setShowHidden(context.showHidden());
- File &file = writerContext.outputFile();
- if (!bConsole)
{
- // TODO: Write a proper synopsis, with all the options.
writerContext.writeTitle("Synopsis");
- writerContext.writeTextBlock(context.moduleDisplayName());
- file.writeLine("\n\n");
+ SynopsisFormatter synopsisFormatter(writerContext);
+ synopsisFormatter.start(context.moduleDisplayName());
+ filter.formatSelected(OptionsFilter::eSelectFileOptions,
+ &synopsisFormatter, impl_->options_);
+ filter.formatSelected(OptionsFilter::eSelectOtherOptions,
+ &synopsisFormatter, impl_->options_);
+ synopsisFormatter.finish();
}
if (impl_->bShowDescriptions_)