2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2013,2014,2015, 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.
35 /*! \libinternal \file
37 * Declares gmx::CommandLineHelpContext.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
41 * \ingroup module_commandline
43 #ifndef GMX_COMMANDLINE_CMDLINEHELPCONTEXT_H
44 #define GMX_COMMANDLINE_CMDLINEHELPCONTEXT_H
46 #include "gromacs/onlinehelp/helpwritercontext.h"
47 #include "gromacs/utility/classhelpers.h"
52 class ShellCompletionWriter;
54 /*! \libinternal \brief
55 * Context information for writing out command-line help.
57 * This class wraps a HelpWriterContext, extending it with information specific
58 * for command-line help export. This way, code using only the routines in the
59 * onlinehelp module is not exposed to extra features of the command-line help
62 * Copying a context works like with HelpWriterContext: the output file and
63 * most state is shared. However, setModuleDisplayName() and setShowHidden()
64 * can be set independently for the child context. Defaults for these options
65 * are inherited from the parent.
67 * \ingroup module_commandline
69 class CommandLineHelpContext
73 * Creates a context for help export.
75 * Wraps the constructor of HelpWriterContext.
77 CommandLineHelpContext(File *file, HelpOutputFormat format,
78 const HelpLinks *links);
79 //! Creates a context for a particular HelpWriterContext.
80 explicit CommandLineHelpContext(const HelpWriterContext &writerContext);
82 * Creates a context for shell completion.
84 explicit CommandLineHelpContext(ShellCompletionWriter *writer);
85 //! Creates a copy of the context.
86 explicit CommandLineHelpContext(const CommandLineHelpContext &other);
87 ~CommandLineHelpContext();
90 * Sets a display name for the module for which help is being written.
92 * \throws std::bad_alloc if out of memory.
94 void setModuleDisplayName(const std::string &name);
95 //! Sets whether hidden options should be shown in help output.
96 void setShowHidden(bool bHidden);
97 //! \copydoc HelpWriterContext::enterSubSection()
98 void enterSubSection(const std::string &title);
100 //! Returns the lower-level context for writing the help.
101 const HelpWriterContext &writerContext() const;
103 * Returns a display name for the module for which help is being written.
107 const char *moduleDisplayName() const;
108 //! Returns whether hidden options should be shown in help output.
109 bool showHidden() const;
110 //! Returns whether this context is for exporting shell completions.
111 bool isCompletionExport() const;
113 * Returns the shell completion writer for this context.
115 * Can only be called if isCompletionExport() returns `true`.
117 ShellCompletionWriter &shellCompletionWriter() const;
122 PrivateImplPointer<Impl> impl_;
124 GMX_DISALLOW_ASSIGN(CommandLineHelpContext);
127 /*! \libinternal \brief
128 * Helper for passing CommandLineHelpContext into parse_common_args().
130 * This class provides a mechanism to set and retrieve a global
131 * CommandLineHelpContext object. It is used to pass this object into
132 * parse_common_args() from CommandLineModuleManager::runAsMainCMain() through
133 * the main() function that is not aware of the wrapper binary mechanism.
134 * It is not thread-safe because in this limited use case, it is always called
135 * from a single-threaded context.
138 * \ingroup module_onlinehelp
140 class GlobalCommandLineHelpContext
143 //! Returns the global context, or NULL if not set.
144 static const CommandLineHelpContext *get();
147 * Sets the global context for the scope.
149 * The global context is cleared when this object goes out of scope.
151 * It is an error to have more than one GlobalCommandLineHelpContext
152 * object in existence at the same time.
154 explicit GlobalCommandLineHelpContext(const CommandLineHelpContext &context);
155 //! Clears the global context.
156 ~GlobalCommandLineHelpContext();