An abstract base class for parsing command-line arguments.
More...
#include <CommandLineParser.h++>
An abstract base class for parsing command-line arguments.
Subclasses must implement processOption() and processNonOptionArguments() and may optionally override handleMissingArgument() and handleInvalidOption().
The registerOption() method should be called once for each option that the parser recognizes. Then, the parseArguments() method may be called to perform the parsing.
- Author
- Mark Lindner
◆ CommandLineParser()
Constructs a new CommandLineParser with the given argument list.
- Parameters
-
| The | argument list to parse. |
◆ ~CommandLineParser()
◆ handleInvalidOption()
| virtual bool handleInvalidOption |
( |
QChar |
opt, |
|
|
const QString & |
longOpt |
|
) |
| |
|
protectedvirtual |
Called to handle an invalid option.
- Parameters
-
| opt | The single-character option, if any, otherwise a NUL character. |
| longOpt | The "long" option, if any, otherwise a null string. |
- Returns
- true if parsing should continue, false otherwise.
◆ handleMissingArgument()
| virtual bool handleMissingArgument |
( |
QChar |
opt, |
|
|
const QString & |
longOpt |
|
) |
| |
|
protectedvirtual |
Called to handle a missing argument error.
- Parameters
-
| opt | The single-character option, if any, otherwise a NUL character. |
| longOpt | The "long" option, if any, otherwise a null string. |
- Returns
- true if parsing should continue, false otherwise.
◆ parseArguments()
◆ printUsage()
Prints usage information based on the options that were registered with registerOption().
This includes a nicely-formatted summary of the available options and their descriptions.
◆ processNonOptionArguments()
| virtual bool processNonOptionArguments |
( |
QStringList |
args | ) |
|
|
protectedpure virtual |
Called to process non-option arguments.
- Parameters
-
- Returns
- true if the arguments were successfully processed, false otherwise.
◆ processOption()
| virtual void processOption |
( |
QChar |
opt, |
|
|
const QString & |
longOpt, |
|
|
const QString & |
arg |
|
) |
| |
|
protectedpure virtual |
Called to process a valid command line option.
- Parameters
-
| opt | The single-character option, if any, otherwise a NUL character. |
| longOpt | The "long" option, if any, otherwise a null string. |
| The | option's argument, if any, otherwise a null string. |
◆ registerOption()
| bool registerOption |
( |
QChar |
opt, |
|
|
const QString & |
longOpt, |
|
|
const QString & |
argName = QString(), |
|
|
const QString & |
description = QString() |
|
) |
| |
Registers a command-line option to be recognized by this parser.
- Parameters
-
| opt | The single-character option, if any, otherwise the NUL character. |
| longOpt | The "long" option, if any, otherwise a null string. |
| argName | The name of the option's argument, if it accepts one, otherwise a null string. |
| description | A description of the option, for the usage message. |
- Returns
- true on success, false otherwise.
The documentation for this class was generated from the following file: