Gromacs
2024.4
|
#include <gromacs/commandline/cmdlineparser.h>
Implements command-line parsing for Options objects.
Typical usage (without error checking):
Classes | |
class | Impl |
Private implementation class for CommandLineParser. More... | |
Public Member Functions | |
CommandLineParser (Options *options) | |
Creates a command-line parser that sets values for options. More... | |
CommandLineParser & | skipUnknown (bool bEnabled) |
Makes the parser skip unknown options and keep them in argv . More... | |
CommandLineParser & | allowPositionalArguments (bool bEnabled) |
Makes the parser accept positional arguments. More... | |
void | parse (int *argc, char *argv[]) |
Parses the command line. More... | |
|
explicit |
Creates a command-line parser that sets values for options.
[in] | options | Options object whose options should be set. |
std::bad_alloc | if out of memory. |
CommandLineParser & gmx::CommandLineParser::allowPositionalArguments | ( | bool | bEnabled | ) |
Makes the parser accept positional arguments.
[in] | bEnabled | Whether to skip and keep positional arguments. |
Arguments that are not options (ie. no leading hyphen), and which come before all options are acceptable if this has been enabled. If so, these arguments are left in argc
and argv
in parse().
The default is false: unknown leading arguments result in exceptions and argc
and argv
are not modified.
Does not throw.
void gmx::CommandLineParser::parse | ( | int * | argc, |
char * | argv[] | ||
) |
Parses the command line.
std::bad_alloc | if out of memory. |
InvalidInputError | if any errors were detected in the input. |
All command-line arguments are parsed, and an aggregate exception with all the detected errors (including unknown options, where applicable) is thrown in the end.
If skipUnknown() was not called, or last called with a false value, the input arguments are not modified. If skipUnknown() was last called with a true value, only unknown options will be retained in argc
and argv
.
All positional arguments are retained in the argument list, but such arguments must precede all options.
argv
[0] is never modified.
CommandLineParser & gmx::CommandLineParser::skipUnknown | ( | bool | bEnabled | ) |
Makes the parser skip unknown options and keep them in argv
.
[in] | bEnabled | Whether to skip and keep unknown options. |
Setting this option to true has dual effect: unknown options are silently skipped, and all recognized options are removed from argc
and argv
in parse(). These effects should be easy to separate into different flags if there is need for it.
The default is false: unknown options result in exceptions and argc
and argv
are not modified.
Does not throw.