{
public:
CommandLineHelpModuleImpl(const ProgramInfo &programInfo,
+ const std::string &binaryName,
const CommandLineModuleMap &modules,
const CommandLineModuleGroupList &groups);
boost::scoped_ptr<RootHelpTopic> rootTopic_;
const ProgramInfo &programInfo_;
+ std::string binaryName_;
const CommandLineModuleMap &modules_;
const CommandLineModuleGroupList &groups_;
void ModuleHelpTopic::writeHelp(const HelpWriterContext & /*context*/) const
{
CommandLineHelpContext context(*helpModule_.context_);
- const char *const program =
- helpModule_.programInfo_.realBinaryName().c_str();
+ const char *const program = helpModule_.binaryName_.c_str();
context.setModuleDisplayName(formatString("%s %s", program, module_.name()));
module_.writeHelp(context);
}
*/
void initProgramLinks(HelpLinks *links, const CommandLineHelpModuleImpl &helpModule)
{
- const char *const program =
- helpModule.programInfo_.realBinaryName().c_str();
+ const char *const program = helpModule.binaryName_.c_str();
CommandLineModuleMap::const_iterator module;
for (module = helpModule.modules_.begin();
module != helpModule.modules_.end();
*/
CommandLineHelpModuleImpl::CommandLineHelpModuleImpl(
const ProgramInfo &programInfo,
+ const std::string &binaryName,
const CommandLineModuleMap &modules,
const CommandLineModuleGroupList &groups)
: rootTopic_(new RootHelpTopic(modules)), programInfo_(programInfo),
- modules_(modules), groups_(groups),
+ binaryName_(binaryName), modules_(modules), groups_(groups),
context_(NULL), moduleOverride_(NULL), bHidden_(false)
{
}
{
// TODO: Would be nicer to have the file names supplied by the build system
// and/or export a list of files from here.
- const char *const program = programInfo_.realBinaryName().c_str();
+ const char *const program = binaryName_.c_str();
exporter->startModuleExport();
CommandLineModuleMap::const_iterator module;
CommandLineHelpModule::CommandLineHelpModule(
const ProgramInfo &programInfo,
+ const std::string &binaryName,
const CommandLineModuleMap &modules,
const CommandLineModuleGroupList &groups)
- : impl_(new Impl(programInfo, modules, groups))
+ : impl_(new Impl(programInfo, binaryName, modules, groups))
{
}
* Creates a command-line help module.
*
* \param[in] programInfo Information about the running binary.
+ * \param[in] binaryName Name of the running binary
+ * (without Gromacs binary suffix or .exe on Windows).
* \param[in] modules List of modules for to use for module listings.
* \param[in] groups List of module groups.
* \throws std::bad_alloc if out of memory.
*/
CommandLineHelpModule(const ProgramInfo &programInfo,
+ const std::string &binaryName,
const CommandLineModuleMap &modules,
const CommandLineModuleGroupList &groups);
~CommandLineHelpModule();
#include "gromacs/utility/programinfo.h"
#include "gromacs/utility/stringutil.h"
+// For GMX_BINARY_SUFFIX
+#include "config.h"
+
namespace gmx
{
/*! \brief
* Initializes the implementation class.
*
+ * \param[in] binaryName Name of the running binary
+ * (without Gromacs binary suffix or .exe on Windows).
* \param programInfo Program information for the running binary.
*/
- explicit Impl(ProgramInfo *programInfo);
+ Impl(const char *binaryName, ProgramInfo *programInfo);
/*! \brief
* Helper method that adds a given module to the module manager.
* \c modules_.end() if not found.
*
* Checks whether the program is invoked through a symlink whose name
- * is different from ProgramInfo::realBinaryName(), and if so, checks
+ * is different from \a binaryName_, and if so, checks
* if a module name matches the name of the symlink.
*
* Note that the \p programInfo parameter is currently not necessary
CommandLineModuleGroupList moduleGroups_;
//! Information about the currently running program.
ProgramInfo &programInfo_;
+ //! Name of the binary.
+ std::string binaryName_;
/*! \brief
* Module that implements help for the binary.
*
GMX_DISALLOW_COPY_AND_ASSIGN(Impl);
};
-CommandLineModuleManager::Impl::Impl(ProgramInfo *programInfo)
- : programInfo_(*programInfo), helpModule_(NULL), singleModule_(NULL),
+CommandLineModuleManager::Impl::Impl(const char *binaryName,
+ ProgramInfo *programInfo)
+ : programInfo_(*programInfo),
+ binaryName_(binaryName != NULL ? binaryName : ""),
+ helpModule_(NULL), singleModule_(NULL),
bQuiet_(false), bStdOutInfo_(false)
{
binaryInfoSettings_.copyright(true);
{
if (helpModule_ == NULL)
{
- helpModule_ = new CommandLineHelpModule(programInfo_, modules_,
- moduleGroups_);
+ helpModule_ = new CommandLineHelpModule(programInfo_, binaryName_,
+ modules_, moduleGroups_);
addModule(CommandLineModulePointer(helpModule_));
}
}
CommandLineModuleManager::Impl::findModuleFromBinaryName(
const ProgramInfo &programInfo) const
{
- std::string binaryName = programInfo.invariantProgramName();
- if (binaryName == programInfo.realBinaryName())
+ std::string moduleName = programInfo.programName();
+#ifdef GMX_BINARY_SUFFIX
+ moduleName = stripSuffixIfPresent(moduleName, GMX_BINARY_SUFFIX);
+#endif
+ if (moduleName == binaryName_)
{
return modules_.end();
}
- if (binaryName.compare(0, 2, "g_") == 0)
+ if (startsWith(moduleName, "g_"))
{
- binaryName.erase(0, 2);
+ moduleName.erase(0, 2);
}
- if (binaryName.compare(0, 3, "gmx") == 0)
+ if (startsWith(moduleName, "gmx"))
{
- binaryName.erase(0, 3);
+ moduleName.erase(0, 3);
}
- return findModuleByName(binaryName);
+ return findModuleByName(moduleName);
}
CommandLineModuleInterface *
{
if (singleModule_ == NULL)
{
- programInfo_.setDisplayName(
- programInfo_.realBinaryName() + " " + module->name());
+ programInfo_.setDisplayName(binaryName_ + " " + 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
* CommandLineModuleManager
*/
-CommandLineModuleManager::CommandLineModuleManager(ProgramInfo *programInfo)
- : impl_(new Impl(programInfo))
+CommandLineModuleManager::CommandLineModuleManager(const char *binaryName,
+ ProgramInfo *programInfo)
+ : impl_(new Impl(binaryName, programInfo))
{
}
CommandLineModuleGroup CommandLineModuleManager::addModuleGroup(
const char *title)
{
- const char *const binaryName =
- impl_->programInfo_.invariantProgramName().c_str();
+ const char *const binaryName = impl_->binaryName_.c_str();
CommandLineModuleGroupDataPointer group(
new CommandLineModuleGroupData(impl_->modules_, binaryName, title));
impl_->moduleGroups_.push_back(move(group));
ProgramInfo &programInfo = gmx::init(&argc, &argv);
try
{
- CommandLineModuleManager manager(&programInfo);
+ CommandLineModuleManager manager(NULL, &programInfo);
manager.setSingleModule(module);
int rc = manager.run(argc, argv);
gmx::finalize();
* \code
int main(int argc, char *argv[])
{
- gmx::ProgramInfo &programInfo = gmx::init("gmx", &argc, &argv);
+ gmx::ProgramInfo &programInfo = gmx::init(&argc, &argv);
try
{
- gmx::CommandLineModuleManager manager(&programInfo);
+ gmx::CommandLineModuleManager manager("gmx", &programInfo);
// <register all necessary modules>
int rc = manager.run(argc, argv);
gmx::finalize();
/*! \brief
* Initializes a command-line module manager.
*
+ * \param[in] binaryName Name of the running binary
+ * (without Gromacs binary suffix or .exe on Windows).
* \param programInfo Program information for the running binary.
* \throws std::bad_alloc if out of memory.
*
- * The binary name is used to detect when the binary is run through a
+ * \p binaryName is used to detect when the binary is run through a
* symlink, and automatically invoke a matching module in such a case.
*
* \p programInfo is non-const to allow the manager to amend it based
* on the actual module that is getting executed.
*/
- explicit CommandLineModuleManager(ProgramInfo *programInfo);
+ CommandLineModuleManager(const char *binaryName,
+ ProgramInfo *programInfo);
~CommandLineModuleManager();
/*! \brief
const CommandLine &args, const char *realBinaryName)
{
manager_.reset();
- programInfo_.reset(new gmx::ProgramInfo(realBinaryName, args.argc(), args.argv()));
- manager_.reset(new gmx::CommandLineModuleManager(programInfo_.get()));
+ programInfo_.reset(new gmx::ProgramInfo(args.argc(), args.argv()));
+ manager_.reset(new gmx::CommandLineModuleManager(realBinaryName, programInfo_.get()));
manager_->setQuiet(true);
}
/*
* 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,2014, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
int
main(int argc, char *argv[])
{
- gmx::ProgramInfo::init(argc, argv);
- try
- {
- gmx::SelectionTester module;
- gmx::TrajectoryAnalysisCommandLineRunner runner(&module);
- runner.setSelectionDebugLevel(1);
- return runner.run(argc, argv);
- }
- catch (const std::exception &ex)
- {
- gmx::printFatalErrorMessage(stderr, ex);
- return 1;
- }
+ return gmx::TrajectoryAnalysisCommandLineRunner::runAsMain<gmx::SelectionTester>(argc, argv);
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
} // namespace
#endif
-ProgramInfo &init(const char *realBinaryName, int *argc, char ***argv)
+ProgramInfo &init(int *argc, char ***argv)
{
#ifdef GMX_LIB_MPI
int isInitialized = 0, isFinalized = 0;
broadcastArguments(&cr, argc, argv);
}
#endif
- return ProgramInfo::init(realBinaryName, *argc, *argv);
-}
-
-ProgramInfo &init(int *argc, char ***argv)
-{
- return init(NULL, argc, argv);
+ return ProgramInfo::init(*argc, *argv);
}
void finalize()
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
{
/*! \brief
- * Initializes the \Gromacs library with explicit binary name.
+ * Initializes the \Gromacs library.
*
- * \param[in] realBinaryName Name of the binary
- * (without Gromacs binary suffix or .exe on Windows).
* \param[in] argc argc value passed to main().
* \param[in] argv argv array passed to main().
* \returns Reference to initialized program information object.
*
- * This overload is provided for cases where the program may be invoked
- * through a symlink, and it is necessary to know the real name of the
- * binary.
- *
* Currently, this is tailored for use in command-line/standalone applications.
* Some additional thought may be required to make it generally usable.
*
*
* \ingroup module_utility
*/
-ProgramInfo &init(const char *realBinaryName, int *argc, char ***argv);
-/*! \brief
- * Initializes the \Gromacs library.
- *
- * \param[in] argc argc value passed to main().
- * \param[in] argv argv array passed to main().
- * \returns Reference to initialized program information object.
- *
- * Does not throw. Terminates the program on out-of-memory error.
- *
- * \ingroup module_utility
- */
ProgramInfo &init(int *argc, char ***argv);
/*! \brief
* Deinitializes the \Gromacs library.
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
{
public:
Impl();
- Impl(const char *realBinaryName, int argc, const char *const argv[],
+ Impl(int argc, const char *const argv[],
ExecutableEnvironmentPointer env);
ExecutableEnvironmentPointer executableEnv_;
- std::string realBinaryName_;
std::string invokedName_;
std::string programName_;
- std::string invariantProgramName_;
std::string displayName_;
std::string commandLine_;
mutable std::string fullBinaryPath_;
};
ProgramInfo::Impl::Impl()
- : realBinaryName_("GROMACS"),
- programName_("GROMACS"), invariantProgramName_("GROMACS")
+ : programName_("GROMACS")
{
}
-ProgramInfo::Impl::Impl(const char *realBinaryName,
- int argc, const char *const argv[],
+ProgramInfo::Impl::Impl(int argc, const char *const argv[],
ExecutableEnvironmentPointer env)
- : executableEnv_(move(env)),
- realBinaryName_(realBinaryName != NULL ? realBinaryName : "")
+ : executableEnv_(move(env))
{
invokedName_ = (argc != 0 ? argv[0] : "");
programName_ = Path::splitToPathAndFilename(invokedName_).second;
programName_ = stripSuffixIfPresent(programName_, ".exe");
- invariantProgramName_ = programName_;
-#ifdef GMX_BINARY_SUFFIX
- invariantProgramName_ =
- stripSuffixIfPresent(invariantProgramName_, GMX_BINARY_SUFFIX);
-#endif
- if (realBinaryName == NULL)
- {
- realBinaryName_ = invariantProgramName_;
- }
commandLine_ = quoteIfNecessary(programName_.c_str());
for (int i = 1; i < argc; ++i)
// static
ProgramInfo &ProgramInfo::init(int argc, const char *const argv[])
-{
- return init(NULL, argc, argv);
-}
-
-// static
-ProgramInfo &ProgramInfo::init(const char *realBinaryName,
- int argc, const char *const argv[])
{
try
{
tMPI::lock_guard<tMPI::mutex> lock(g_programInfoMutex);
if (g_programInfo.get() == NULL)
{
- g_programInfo.reset(new ProgramInfo(realBinaryName, argc, argv));
+ g_programInfo.reset(new ProgramInfo(argc, argv));
}
return *g_programInfo;
}
{
}
-ProgramInfo::ProgramInfo(const char *realBinaryName)
- : impl_(new Impl(realBinaryName, 1, &realBinaryName,
+ProgramInfo::ProgramInfo(const char *binaryName)
+ : impl_(new Impl(1, &binaryName,
DefaultExecutableEnvironment::create()))
{
}
ProgramInfo::ProgramInfo(int argc, const char *const argv[])
- : impl_(new Impl(NULL, argc, argv,
+ : impl_(new Impl(argc, argv,
DefaultExecutableEnvironment::create()))
{
}
-ProgramInfo::ProgramInfo(const char *realBinaryName,
- int argc, const char *const argv[])
- : impl_(new Impl(realBinaryName, argc, argv,
- DefaultExecutableEnvironment::create()))
-{
-}
-
-ProgramInfo::ProgramInfo(const char *realBinaryName,
- int argc, const char *const argv[],
+ProgramInfo::ProgramInfo(int argc, const char *const argv[],
ExecutableEnvironmentPointer env)
- : impl_(new Impl(realBinaryName, argc, argv, move(env)))
+ : impl_(new Impl(argc, argv, move(env)))
{
}
impl_->displayName_ = name;
}
-const std::string &ProgramInfo::realBinaryName() const
-{
- return impl_->realBinaryName_;
-}
-
const std::string &ProgramInfo::programName() const
{
return impl_->programName_;
}
-const std::string &ProgramInfo::invariantProgramName() const
-{
- return impl_->invariantProgramName_;
-}
-
const std::string &ProgramInfo::displayName() const
{
tMPI::lock_guard<tMPI::mutex> lock(impl_->displayNameMutex_);
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
* \param[in] argv argv array passed to main().
* \returns Reference to initialized program information object.
*
- * The return value of realBinaryName() is the same as
- * invariantProgramName().
- *
* Does not throw. Terminates the program on out-of-memory error.
*/
static ProgramInfo &init(int argc, const char *const argv[]);
- /*! \brief
- * Initializes global program information with explicit binary name.
- *
- * \param[in] realBinaryName Name of the binary
- * (without Gromacs binary suffix or .exe on Windows).
- * \param[in] argc argc value passed to main().
- * \param[in] argv argv array passed to main().
- * \returns Reference to initialized program information object.
- *
- * This overload is provided for cases where the program may be invoked
- * through a symlink, and it is necessary to know the real name of the
- * binary.
- *
- * Does not throw. Terminates the program on out-of-memory error.
- */
- static ProgramInfo &init(const char *realBinaryName,
- int argc, const char *const argv[]);
/*! \brief
* Constructs an empty program info objects.
/*! \brief
* Initializes a program information object with binary name only.
*
- * \param[in] realBinaryName Name of the binary
- * (without Gromacs binary suffix or .exe on Windows).
+ * \param[in] binaryName Name of the binary.
*
* This is needed for unit testing purposes.
* The constructed object works as if the command line consisted of
* only of the binary name.
*/
- explicit ProgramInfo(const char *realBinaryName);
+ explicit ProgramInfo(const char *binaryName);
/*! \brief
* Initializes a program information object based on command line.
*
* Initializes a program information object based on binary name and
* command line.
*
- * \param[in] realBinaryName Name of the binary
- * (without Gromacs binary suffix or .exe on Windows).
- * \param[in] argc argc value passed to main().
- * \param[in] argv argv array passed to main().
- */
- ProgramInfo(const char *realBinaryName,
- int argc, const char *const argv[]);
- /*! \brief
- * Initializes a program information object based on binary name and
- * command line.
- *
- * \param[in] realBinaryName Name of the binary
- * (without Gromacs binary suffix or .exe on Windows).
* \param[in] argc argc value passed to main().
* \param[in] argv argv array passed to main().
* \param[in] env Customizes the way the binary name is handled.
* into a non-Gromacs executable (with possible extensions in
* ExecutableEnvironmentInterface).
*/
- ProgramInfo(const char *realBinaryName,
- int argc, const char *const argv[],
+ ProgramInfo(int argc, const char *const argv[],
ExecutableEnvironmentPointer env);
~ProgramInfo();
*/
void setDisplayName(const std::string &name);
- /*! \brief
- * Returns the real name of the binary.
- *
- * The returned value is comparable to invariantProgramName(), i.e., it
- * has suffixes and OS-specific extensions removed.
- *
- * Does not throw.
- */
- const std::string &realBinaryName() const;
/*! \brief
* Returns the name of the binary as it was invoked without any path.
*
* Does not throw.
*/
const std::string &programName() const;
- /*! \brief
- * Returns an invariant name of the binary.
- *
- * The returned value has OS-specific extensions (.exe on Windows)
- * removed, as well as any binary suffix that was configured.
- *
- * Does not throw.
- */
- const std::string &invariantProgramName() const;
/*! \brief
* Returns a display name of the current module.
*
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
void testBinaryPathSearch(const char *argv0)
{
ASSERT_TRUE(env_.get() != NULL);
- gmx::ProgramInfo info(NULL, 1, &argv0, move(env_));
+ gmx::ProgramInfo info(1, &argv0, move(env_));
EXPECT_EQ(expectedExecutable_, info.fullBinaryPath());
}
void testBinaryPathSearch(const std::string &argv0)
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
int
main(int argc, char *argv[])
{
- gmx::ProgramInfo &info = gmx::init("gmx", &argc, &argv);
+ gmx::ProgramInfo &info = gmx::init(&argc, &argv);
try
{
- gmx::CommandLineModuleManager manager(&info);
+ gmx::CommandLineModuleManager manager("gmx", &info);
registerTrajectoryAnalysisModules(&manager);
registerLegacyModules(&manager);
manager.addHelpTopic(gmx::SelectionCollection::createDefaultHelpTopic());