public:
//! Creates the implementation class and the low-level context.
Impl(File *file, HelpOutputFormat format)
- : writerContext_(file, format), moduleDisplayName_("gmx")
+ : writerContext_(file, format), moduleDisplayName_("gmx"),
+ bHidden_(false)
{
}
HelpWriterContext writerContext_;
//! Display name for the module for which help is written.
std::string moduleDisplayName_;
+ //! Whether hidden options should be shown in help output.
+ bool bHidden_;
};
CommandLineHelpContext::CommandLineHelpContext(
impl_->moduleDisplayName_ = name;
}
+
+void CommandLineHelpContext::setShowHidden(bool bHidden)
+{
+ impl_->bHidden_ = bHidden;
+}
+
const HelpWriterContext &CommandLineHelpContext::writerContext() const
{
return impl_->writerContext_;
return impl_->moduleDisplayName_.c_str();
}
+bool CommandLineHelpContext::showHidden() const
+{
+ return impl_->bHidden_;
+}
+
/********************************************************************
* GlobalCommandLineHelpContext
*/
* \throws std::bad_alloc if out of memory.
*/
void setModuleDisplayName(const std::string &name);
+ //! Sets whether hidden options should be shown in help output.
+ void setShowHidden(bool bHidden);
//! Returns the lower-level context for writing the help.
const HelpWriterContext &writerContext() const;
* Does not throw.
*/
const char *moduleDisplayName() const;
+ //! Returns whether hidden options should be shown in help output.
+ bool showHidden() const;
private:
class Impl;
std::string timeUnit_;
//! Whether to write descriptions to output.
bool bShowDescriptions_;
- //! Whether to write hidden options to output.
- bool bShowHidden_;
};
CommandLineHelpWriter::Impl::Impl(const Options &options)
: options_(options), timeUnit_(TimeUnitManager().timeUnitAsString()),
- bShowDescriptions_(false), bShowHidden_(false)
+ bShowDescriptions_(false)
{
}
{
}
-CommandLineHelpWriter &CommandLineHelpWriter::setShowHidden(bool bSet)
-{
- impl_->bShowHidden_ = bSet;
- return *this;
-}
-
CommandLineHelpWriter &CommandLineHelpWriter::setShowDescriptions(bool bSet)
{
impl_->bShowDescriptions_ = bSet;
"Command-line help is not implemented for this output format"));
}
OptionsFilter filter(writerContext, formatter.get());
- filter.setShowHidden(impl_->bShowHidden_);
+ filter.setShowHidden(context.showHidden());
if (impl_->bShowDescriptions_)
{
explicit CommandLineHelpWriter(const Options &options);
~CommandLineHelpWriter();
- /*! \brief
- * Sets whether hidden options are shown in the help.
- */
- CommandLineHelpWriter &setShowHidden(bool bShow);
/*! \brief
* Sets whether long descriptions for sections are shown in the help.
*/
//! Container type for mapping module names to module objects.
typedef std::map<std::string, CommandLineModulePointer> CommandLineModuleMap;
+class CommandLineHelpModule;
+
namespace
{
}
/********************************************************************
- * ModuleHelpTopic
+ * ModuleHelpTopic declaration
*/
/*! \internal \brief
{
public:
//! Constructs a help topic for a specific module.
- explicit ModuleHelpTopic(const CommandLineModuleInterface &module)
- : module_(module)
+ ModuleHelpTopic(const CommandLineModuleInterface &module,
+ const CommandLineHelpModule &helpModule)
+ : module_(module), helpModule_(helpModule)
{
}
private:
const CommandLineModuleInterface &module_;
+ const CommandLineHelpModule &helpModule_;
GMX_DISALLOW_COPY_AND_ASSIGN(ModuleHelpTopic);
};
-void ModuleHelpTopic::writeHelp(const HelpWriterContext &context) const
-{
- CommandLineHelpContext newContext(&context.outputFile(),
- context.outputFormat());
- module_.writeHelp(newContext);
-}
-
/********************************************************************
* HelpExportInterface
*/
* \throws std::bad_alloc if out of memory.
*/
void addTopic(HelpTopicPointer topic);
+ //! Sets whether hidden options will be shown in help.
+ void setShowHidden(bool bHidden) { bHidden_ = bHidden; }
+ /*! \brief
+ * Sets an override to show the help for the given module.
+ *
+ * If called, the help module directly prints the help for the given
+ * module when called, skipping any other processing.
+ */
+ void setModuleOverride(const CommandLineModuleInterface &module)
+ {
+ moduleOverride_ = &module;
+ }
+
+ //! Returns the context object for help output.
+ const CommandLineHelpContext &context() const
+ {
+ return *context_;
+ }
virtual const char *name() const { return "help"; }
virtual const char *shortDescription() const
boost::scoped_ptr<RootHelpTopic> rootTopic_;
const CommandLineModuleMap &modules_;
+ CommandLineHelpContext *context_;
+ const CommandLineModuleInterface *moduleOverride_;
+ bool bHidden_;
+
GMX_DISALLOW_COPY_AND_ASSIGN(CommandLineHelpModule);
};
CommandLineHelpModule::CommandLineHelpModule(const CommandLineModuleMap &modules)
- : rootTopic_(new RootHelpTopic(modules)), modules_(modules)
+ : rootTopic_(new RootHelpTopic(modules)), modules_(modules),
+ context_(NULL), moduleOverride_(NULL), bHidden_(false)
{
}
return 0;
}
- HelpWriterContext context(&File::standardOutput(),
- eHelpOutputFormat_Console);
- HelpManager helpManager(*rootTopic_, context);
+ boost::scoped_ptr<CommandLineHelpContext> context(
+ new CommandLineHelpContext(&File::standardOutput(),
+ eHelpOutputFormat_Console));
+ context->setShowHidden(bHidden_);
+ context_ = context.get();
+ if (moduleOverride_ != NULL)
+ {
+ ModuleHelpTopic(*moduleOverride_, *this).writeHelp(context->writerContext());
+ return 0;
+ }
+
+ HelpManager helpManager(*rootTopic_, context->writerContext());
try
{
for (int i = 1; i < argc; ++i)
namespace
{
+/********************************************************************
+ * ModuleHelpTopic implementation
+ */
+
+void ModuleHelpTopic::writeHelp(const HelpWriterContext & /*context*/) const
+{
+ module_.writeHelp(helpModule_.context());
+}
+
/********************************************************************
* CMainCommandLineModule
*/
virtual void writeHelp(const CommandLineHelpContext &context) const
{
const HelpOutputFormat format = context.writerContext().outputFormat();
- char *argv[2];
- int argc = 1;
- // TODO: The constness should not be cast away.
- argv[0] = const_cast<char *>(name_);
+ const char *type;
switch (format)
{
case eHelpOutputFormat_Console:
- argv[1] = const_cast<char *>("-h");
- argc = 2;
+ type = "help";
break;
default:
GMX_THROW(NotImplementedError(
"Command-line help is not implemented for this output format"));
}
+ char *argv[4];
+ int argc = 3;
+ // TODO: The constness should not be cast away.
+ argv[0] = const_cast<char *>(name_);
+ argv[1] = const_cast<char *>("-man");
+ argv[2] = const_cast<char *>(type);
+ argv[3] = NULL;
GlobalCommandLineHelpContext global(context);
mainFunction_(argc, argv);
}
*/
explicit Impl(ProgramInfo *programInfo);
+ /*! \brief
+ * Helper method that adds a given module to the module manager.
+ *
+ * \throws std::bad_alloc if out of memory.
+ */
+ void addModule(CommandLineModulePointer module);
+ /*! \brief
+ * Creates the help module if it does not yet exist.
+ *
+ * \throws std::bad_alloc if out of memory.
+ *
+ * This method should be called before accessing \a helpModule_.
+ */
+ void ensureHelpModuleExists();
+
/*! \brief
* Finds a module that matches a name.
*
binaryInfoSettings_.copyright(true);
}
+void CommandLineModuleManager::Impl::addModule(CommandLineModulePointer module)
+{
+ GMX_ASSERT(modules_.find(module->name()) == modules_.end(),
+ "Attempted to register a duplicate module name");
+ ensureHelpModuleExists();
+ HelpTopicPointer helpTopic(new ModuleHelpTopic(*module, *helpModule_));
+ modules_.insert(std::make_pair(std::string(module->name()),
+ move(module)));
+ helpModule_->addTopic(move(helpTopic));
+}
+
+void CommandLineModuleManager::Impl::ensureHelpModuleExists()
+{
+ if (helpModule_ == NULL)
+ {
+ helpModule_ = new CommandLineHelpModule(modules_);
+ addModule(CommandLineModulePointer(helpModule_));
+ }
+}
+
CommandLineModuleMap::const_iterator
CommandLineModuleManager::Impl::findModuleByName(const std::string &name) const
{
}
bool bHelp = false;
+ bool bHidden = false;
bool bVersion = false;
bool bCopyright = true;
// TODO: Print the common options into the help.
// TODO: It would be nice to propagate at least the -quiet option to
// the modules so that they can also be quiet in response to this.
- // TODO: Consider handling -h and related options here instead of in the
- // modules (also -hidden needs to be transfered here to make that work).
- // That would mean that with -h, all module-specific options would get
- // ignored. This means that the help output would not depend on the
- // command line, but would always show the default values (making it
- // possible to simplify it further), but also that mdrun -h could not be
- // used for option validation in g_tune_pme.
Options options(NULL, NULL);
- if (module == NULL)
- {
- options.addOption(BooleanOption("h").store(&bHelp));
- }
+ options.addOption(BooleanOption("h").store(&bHelp));
+ options.addOption(BooleanOption("hidden").store(&bHidden));
options.addOption(BooleanOption("quiet").store(&bQuiet_));
options.addOption(BooleanOption("version").store(&bVersion));
options.addOption(BooleanOption("copyright").store(&bCopyright));
// which path is taken: (*argv)[0] is the module name.
}
}
- else
+ if (module != NULL)
{
- // In single-module mode, recognize the common options also after the
- // module name.
+ // Recognize the common options also after the module name.
+ // TODO: It could be nicer to only recognize -h/-hidden if module is not
+ // null.
CommandLineParser(&options).skipUnknown(true).parse(argc, *argv);
}
options.finish();
}
// If no module specified and no other action, show the help.
// Also explicitly specifying -h for the wrapper binary goes here.
- if (module == NULL)
+ if (module == NULL || bHelp)
{
- *argc = 1;
- return helpModule_;
+ ensureHelpModuleExists();
+ if (module != NULL)
+ {
+ helpModule_->setModuleOverride(*module);
+ }
+ *argc = 1;
+ module = helpModule_;
+ }
+ if (module == helpModule_)
+ {
+ helpModule_->setShowHidden(bHidden);
}
return module;
}
void CommandLineModuleManager::addModule(CommandLineModulePointer module)
{
- GMX_ASSERT(impl_->modules_.find(module->name()) == impl_->modules_.end(),
- "Attempted to register a duplicate module name");
- HelpTopicPointer helpTopic(new ModuleHelpTopic(*module));
- impl_->modules_.insert(std::make_pair(std::string(module->name()),
- move(module)));
- addHelpTopic(move(helpTopic));
+ impl_->addModule(move(module));
}
void CommandLineModuleManager::addModuleCMain(
void CommandLineModuleManager::addHelpTopic(HelpTopicPointer topic)
{
- if (impl_->helpModule_ == NULL)
- {
- impl_->helpModule_ = new CommandLineHelpModule(impl_->modules_);
- addModule(CommandLineModulePointer(impl_->helpModule_));
- }
+ impl_->ensureHelpModuleExists();
impl_->helpModule_->addTopic(move(topic));
}
class CommandLineHelpWriterTest : public ::gmx::test::StringTestBase
{
public:
+ CommandLineHelpWriterTest() : bHidden_(false) {}
+
void checkHelp(gmx::CommandLineHelpWriter *writer);
gmx::test::TestFileManager tempFiles_;
+ bool bHidden_;
};
void CommandLineHelpWriterTest::checkHelp(gmx::CommandLineHelpWriter *writer)
std::string filename = tempFiles_.getTemporaryFilePath("helptext.txt");
gmx::File file(filename, "w");
gmx::CommandLineHelpContext context(&file, gmx::eHelpOutputFormat_Console);
+ context.setShowHidden(bHidden_);
writer->writeHelp(context);
file.close();
options.addOption(SelectionOption("sel").description("Selection option"));
CommandLineHelpWriter writer(options);
- writer.setShowHidden(true);
+ bHidden_ = true;
checkHelp(&writer);
}
ASSERT_EQ(0, rc);
}
+TEST_F(CommandLineModuleManagerTest, RunsModuleHelpWithDashH)
+{
+ const char *const cmdline[] = {
+ "g_test", "module", "-h"
+ };
+ CommandLine args(CommandLine::create(cmdline));
+ initManager(args);
+ MockModule &mod1 = addModule("module", "First module");
+ addModule("other", "Second module");
+ using ::testing::_;
+ EXPECT_CALL(mod1, writeHelp(_));
+ int rc = 0;
+ ASSERT_NO_THROW_GMX(rc = manager().run(args.argc(), args.argv()));
+ ASSERT_EQ(0, rc);
+}
+
TEST_F(CommandLineModuleManagerTest, PrintsHelpOnTopic)
{
const char *const cmdline[] = {
snew(command, length + 15);
snew(msg, length + 500);
- fprintf(stdout, "Making shure the benchmarks can be executed ...\n");
+ fprintf(stdout, "Making sure the benchmarks can be executed ...\n");
+ /* FIXME: mdrun -h no longer actually does anything useful.
+ * It unconditionally prints the help, ignoring all other options. */
sprintf(command, "%s-h -quiet", mdrun_cmd_line);
ret = gmx_system_call(command);
#define OPTLEN 12
#define TYPELEN 6
#define LONGSTR 1024
-char *pargs_print_line(t_pargs *pa, gmx_bool bLeadingSpace)
+static char *pargs_print_line(t_pargs *pa)
{
char buf[LONGSTR], *buf2, *tmp, *desc;
desc = check_tty(pa->desc);
if (strlen(buf) > ((OPTLEN+TYPELEN)-max(strlen(get_arg_desc(pa->type)), 4)))
{
- sprintf(buf2, "%s%s %-6s %-6s %-s\n",
- bLeadingSpace ? " " : "", buf,
- get_arg_desc(pa->type), pa_val(pa, tmp, LONGSTR-1), desc);
+ sprintf(buf2, "%s %-6s %-6s %-s\n",
+ buf, get_arg_desc(pa->type), pa_val(pa, tmp, LONGSTR-1), desc);
}
else if (strlen(buf) > OPTLEN)
{
/* so type can be 3 or 4 char's, this fits in the %4s */
- sprintf(buf2, "%s%-14s %-4s %-6s %-s\n",
- bLeadingSpace ? " " : "", buf, get_arg_desc(pa->type),
- pa_val(pa, tmp, LONGSTR-1), desc);
+ sprintf(buf2, "%-14s %-4s %-6s %-s\n",
+ buf, get_arg_desc(pa->type), pa_val(pa, tmp, LONGSTR-1), desc);
}
else
{
- sprintf(buf2, "%s%-12s %-6s %-6s %-s\n",
- bLeadingSpace ? " " : "", buf, get_arg_desc(pa->type),
- pa_val(pa, tmp, LONGSTR-1), desc);
+ sprintf(buf2, "%-12s %-6s %-6s %-s\n",
+ buf, get_arg_desc(pa->type), pa_val(pa, tmp, LONGSTR-1), desc);
}
sfree(desc);
sfree(tmp);
return tmp;
}
-void print_pargs(FILE *fp, int npargs, t_pargs pa[], gmx_bool bLeadingSpace)
+void print_pargs(FILE *fp, int npargs, t_pargs pa[])
{
- gmx_bool bShowHidden;
char buf[32], buf2[256], tmp[256];
char *wdesc;
int i;
- /* Cannot call opt2parg_bSet here, because it crashes when the option
- * is not in the list (mdrun)
- */
- bShowHidden = FALSE;
- for (i = 0; (i < npargs); i++)
- {
- if ((strcmp(pa[i].option, "-hidden") == 0) && (pa[i].bSet))
- {
- bShowHidden = TRUE;
- }
- }
if (npargs > 0)
{
- fprintf(fp, "%s%-12s %-6s %-6s %-s\n",
- bLeadingSpace ? " " : "", "Option", "Type", "Value", "Description");
- fprintf(fp, "%s------------------------------------------------------\n",
- bLeadingSpace ? " " : "");
+ fprintf(fp, "%-12s %-6s %-6s %-s\n",
+ "Option", "Type", "Value", "Description");
+ fprintf(fp, "------------------------------------------------------\n");
for (i = 0; (i < npargs); i++)
{
- if (bShowHidden || !is_hidden(&pa[i]))
- {
- wdesc = pargs_print_line(&pa[i], bLeadingSpace);
- fprintf(fp, "%s", wdesc);
- sfree(wdesc);
- }
+ wdesc = pargs_print_line(&pa[i]);
+ fprintf(fp, "%s", wdesc);
+ sfree(wdesc);
}
fprintf(fp, "\n");
}
int nbugs, const char **bugs,
output_env_t *oenv)
{
- gmx_bool bHelp = FALSE, bHidden = FALSE, bVerbose = FALSE;
const char *manstr[] = {
- NULL, "no", "html", "tex", "nroff", "completion", NULL
+ NULL, "no", "help", "html", "tex", "nroff", "completion", NULL
};
/* This array should match the order of the enum in oenv.h */
const char *xvg_format[] = { NULL, "xmgrace", "xmgr", "none", NULL };
#define EXTRA_PA 16
t_pargs pca_pa[] = {
- { "-h", FALSE, etBOOL, {&bHelp},
- "Print help info and quit" },
- { "-verbose", FALSE, etBOOL, {&bVerbose},
- "HIDDENShow options during normal run" },
- { "-hidden", FALSE, etBOOL, {&bHidden},
- "HIDDENPrint hidden options" },
{ "-man", FALSE, etENUM, {manstr},
"HIDDENWrite manual and quit" },
{ "-debug", FALSE, etINT, {&debug_level},
all_pa[i].desc = mk_desc(&(all_pa[i]), output_env_get_time_unit(*oenv));
}
- bExit = bHelp || (strcmp(manstr[0], "no") != 0);
+ // To satisfy clang.
+ GMX_ASSERT(manstr[0] != NULL,
+ "Enum option default assignment should have changed this");
+ bExit = (strcmp(manstr[0], "no") != 0);
#if (defined __sgi && USE_SGI_FPE)
doexceptions();
#endif
#endif
- if (!(FF(PCA_QUIET)))
- {
- if (bHelp)
- {
- write_man("help", output_env_get_program_name(*oenv),
- ndesc, desc, nfile, fnm, npall, all_pa, nbugs, bugs, bHidden);
- }
- else if (bVerbose)
- {
- pr_fns(stderr, nfile, fnm);
- print_pargs(stderr, npall, all_pa, FALSE);
- }
- }
-
- if (strcmp(manstr[0], "no") != 0)
+ if (strcmp(manstr[0], "no") != 0 && !(FF(PCA_QUIET)))
{
if (!strcmp(manstr[0], "completion"))
{
/* one file each for csh, bash and zsh if we do completions */
write_man("completion-zsh", output_env_get_short_program_name(*oenv),
- ndesc, desc, nfile, fnm, npall, all_pa, nbugs, bugs, bHidden);
+ ndesc, desc, nfile, fnm, npall, all_pa, nbugs, bugs);
write_man("completion-bash", output_env_get_short_program_name(*oenv),
- ndesc, desc, nfile, fnm, npall, all_pa, nbugs, bugs, bHidden);
+ ndesc, desc, nfile, fnm, npall, all_pa, nbugs, bugs);
write_man("completion-csh", output_env_get_short_program_name(*oenv),
- ndesc, desc, nfile, fnm, npall, all_pa, nbugs, bugs, bHidden);
+ ndesc, desc, nfile, fnm, npall, all_pa, nbugs, bugs);
}
else
{
write_man(manstr[0], output_env_get_short_program_name(*oenv),
- ndesc, desc, nfile, fnm, npall, all_pa, nbugs, bugs, bHidden);
+ ndesc, desc, nfile, fnm, npall, all_pa, nbugs, bugs);
}
}
gmx_bool opt2parg_bSet(const char *option, int nparg, t_pargs pa[]);
-void print_pargs(FILE *fp, int npargs, t_pargs pa[], gmx_bool bLeadingSpace);
-
-char *pargs_print_line(t_pargs *pa, gmx_bool bLeadingSpace);
+void print_pargs(FILE *fp, int npargs, t_pargs pa[]);
void pr_enums(FILE *fp, int npargs, t_pargs pa[], int shell);
}
if (npargs > 0)
{
- print_pargs(out, npargs, pa, FALSE);
+ print_pargs(out, npargs, pa);
}
}
int nldesc, const char **desc,
int nfile, t_filenm *fnm,
int npargs, t_pargs *pa,
- int nbug, const char **bugs,
- gmx_bool bHidden)
+ int nbug, const char **bugs)
{
- int i, npar;
+ bool bHidden = false;
+ int npar;
t_pargs *par;
t_linkdata *links;
FILE *out;
if (context != NULL)
{
- out = context->writerContext().outputFile().handle();
- }
- else if (strcmp(mantp, "help") == 0)
- {
- out = stderr;
+ out = context->writerContext().outputFile().handle();
+ bHidden = context->showHidden();
}
else
{
{
snew(par, npargs);
npar = 0;
- for (i = 0; i < npargs; i++)
+ for (int i = 0; i < npargs; i++)
{
if (!is_hidden(&pa[i]))
{
int nldesc, const char **desc,
int nfile, t_filenm *fnm,
int npargs, t_pargs *pa,
- int nbug, const char **bugs,
- gmx_bool bHidden);
+ int nbug, const char **bugs);
char *fileopt(unsigned long flag, char buf[], int maxsize);
/* Return a string describing the file type in flag.
#include "gromacs/commandline/cmdlinemodule.h"
#include "gromacs/commandline/cmdlinemodulemanager.h"
#include "gromacs/commandline/cmdlineparser.h"
-#include "gromacs/onlinehelp/helpwritercontext.h"
#include "gromacs/options/options.h"
#include "gromacs/selection/selectioncollection.h"
#include "gromacs/selection/selectionoptionmanager.h"
Impl(TrajectoryAnalysisModule *module);
~Impl();
- void printHelp(const Options &options,
- const TrajectoryAnalysisSettings &settings,
- const TrajectoryAnalysisRunnerCommon &common);
bool parseOptions(TrajectoryAnalysisSettings *settings,
TrajectoryAnalysisRunnerCommon *common,
SelectionCollection *selections,
}
-void
-TrajectoryAnalysisCommandLineRunner::Impl::printHelp(
- const Options &options,
- const TrajectoryAnalysisSettings &settings,
- const TrajectoryAnalysisRunnerCommon &common)
-{
- TrajectoryAnalysisRunnerCommon::HelpFlags flags = common.helpFlags();
- if (flags != 0)
- {
- CommandLineHelpContext context(&File::standardError(),
- eHelpOutputFormat_Console);
- CommandLineHelpWriter(options)
- .setShowDescriptions(flags & TrajectoryAnalysisRunnerCommon::efHelpShowDescriptions)
- .setShowHidden(flags & TrajectoryAnalysisRunnerCommon::efHelpShowHidden)
- .setTimeUnitString(settings.timeUnitManager().timeUnitAsString())
- .writeHelp(context);
- }
-}
-
-
bool
TrajectoryAnalysisCommandLineRunner::Impl::parseOptions(
TrajectoryAnalysisSettings *settings,
{
CommandLineParser parser(&options);
- try
- {
- parser.parse(argc, argv);
- }
- catch (const UserInputError &ex)
- {
- printHelp(options, *settings, *common);
- throw;
- }
- printHelp(options, *settings, *common);
+ // TODO: Print the help if user provides an invalid option?
+ // Or just add a message advising the user to invoke the help?
+ parser.parse(argc, argv);
common->scaleTimeOptions(&options);
options.finish();
}
- if (!common->optionsFinished(&commonOptions))
- {
- return false;
- }
+ common->optionsFinished(&commonOptions);
module_->optionsFinished(&moduleOptions, settings);
common->initIndexGroups(selections);
void
TrajectoryAnalysisCommandLineRunner::writeHelp(const CommandLineHelpContext &context)
{
- // TODO: This method duplicates some code from run() and Impl::printHelp().
+ // TODO: This method duplicates some code from run().
// See how to best refactor it to share the common code.
SelectionCollection selections;
TrajectoryAnalysisSettings settings;
TrajectoryAnalysisSettings &settings_;
TopologyInformation topInfo_;
- bool bHelp_;
- bool bShowHidden_;
- bool bVerbose_;
//! Name of the trajectory file (empty if not provided).
std::string trjfile_;
//! Name of the topology file (empty if no topology provided).
TrajectoryAnalysisRunnerCommon::Impl::Impl(TrajectoryAnalysisSettings *settings)
: settings_(*settings),
- bHelp_(false), bShowHidden_(false), bVerbose_(false),
startTime_(0.0), endTime_(0.0), deltaTime_(0.0),
grps_(NULL),
bTrajOpen_(false), fr(NULL), gpbc_(NULL), status_(NULL), oenv_(NULL)
{
TrajectoryAnalysisSettings &settings = impl_->settings_;
- // Add options for help.
- options->addOption(BooleanOption("h").store(&impl_->bHelp_)
- .description("Print help and quit"));
- options->addOption(BooleanOption("hidden").store(&impl_->bShowHidden_)
- .hidden()
- .description("Show hidden options"));
- options->addOption(BooleanOption("verbose").store(&impl_->bVerbose_)
- .hidden()
- .description("Show options during normal run"));
-
// Add common file name arguments.
options->addOption(FileNameOption("f")
.filetype(eftTrajectory).inputFile()
}
-bool
+void
TrajectoryAnalysisRunnerCommon::optionsFinished(Options *options)
{
- if (impl_->bHelp_)
- {
- return false;
- }
-
impl_->settings_.impl_->plotSettings.setTimeUnit(
impl_->settings_.impl_->timeUnitManager.timeUnit());
{
setTimeValue(TDELTA, impl_->deltaTime_);
}
-
- return true;
}
}
-TrajectoryAnalysisRunnerCommon::HelpFlags
-TrajectoryAnalysisRunnerCommon::helpFlags() const
-{
- HelpFlags flags = 0;
-
- if (impl_->bVerbose_)
- {
- flags |= efHelpShowOptions;
- }
- if (impl_->bHelp_)
- {
- flags |= efHelpShowOptions;
- flags |= efHelpShowDescriptions;
- }
- if (flags != 0 && impl_->bShowHidden_)
- {
- flags |= efHelpShowHidden;
- }
- return flags;
-}
-
bool
TrajectoryAnalysisRunnerCommon::hasTrajectory() const
{
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by
* David van der Spoel, Berk Hess, Erik Lindahl, and including many
* others, as listed in the AUTHORS file in the top-level source
* directory and at http://www.gromacs.org.
class TrajectoryAnalysisRunnerCommon
{
public:
- /*! \brief
- * Flags that define what kind of help should be printed.
- */
- enum HelpFlag
- {
- efHelpShowOptions = 1<<0, //!< Show options.
- efHelpShowHidden = 1<<1, //!< Show hidden options.
- efHelpShowDescriptions = 1<<2 //!< Show detailed description.
- };
- //! Combination of \ref HelpFlag values.
- typedef unsigned long HelpFlags;
-
/*! \brief
* Initializes a new runner helper.
*
* Processes common option values after they have been parsed.
*
* \param[in,out] options Options object in which options are stored.
- * \returns false if the tool should exit after printing help.
*/
- bool optionsFinished(Options *options);
+ void optionsFinished(Options *options);
//! Initialize index groups for selections.
void initIndexGroups(SelectionCollection *selections);
//! Free memory allocated for index groups.
*/
void initFrame();
- //! Returns flags for help printing.
- HelpFlags helpFlags() const;
//! Returns true if input data comes from a trajectory.
bool hasTrajectory() const;
//! Returns the topology information object.