libcyberradio  22.01.24
AppOptionParser Class Reference

Parses command-line options supported by the application. More...

#include <App.h>

Public Member Functions

 AppOptionParser ()
 Constructs an AppOptionParser object.
 
virtual ~AppOptionParser ()
 Destroys an AppOptionParser object.
 
void allowUnknownOption (bool allow=true)
 Determines whether or not the parser will allow unknown options to pass through the parser without generating an error. More...
 
void setDescription (const std::string &description)
 Sets the portion of the usage information where the application description is displayed. More...
 
void setDisplayWidth (int displayWidth=75)
 Sets the display width of the usage information. More...
 
void setEpilogText (const std::string &epilogText)
 Sets the epilog portion of the usage information; that is, the part that comes after the list of supported options. More...
 
void setExecutable (const std::string &executable)
 Sets the portion of the usage information where the executable name is displayed. More...
 
void setUnparsedArgText (const std::string &unparsedArgText)
 Sets the portion of the usage information that represents the collection of unparsed arguments. More...
 
void setVersion (const std::string &version)
 Sets the portion of the usage information that represents the application version. More...
 
virtual void addOption (const AppOption &opt)
 Adds an allowed option to the parser. More...
 
virtual void addOption (const std::string &shortName, const std::string &longName, int valueType, void *valuePtr, const std::string &helpArgName, const std::string &helpText, bool showDefault)
 Adds an allowed option to the parser. More...
 
virtual int parse (int argc, char **argv)
 Parses the command-line options. More...
 

Data Fields

BasicStringList unparsedArgs
 The collection of arguments that were not dealt with by the parser during option parsing.
 

Detailed Description

Parses command-line options supported by the application.

The option parser defines the following options by default: –help Prints help text and exits –version Prints version information and exits

Definition at line 248 of file App.h.

Member Function Documentation

◆ addOption() [1/2]

void addOption ( const AppOption opt)
virtual

Adds an allowed option to the parser.

Parameters
optAn AppOption object describing the option to add to the parser.

Definition at line 247 of file App.cpp.

◆ addOption() [2/2]

void addOption ( const std::string &  shortName,
const std::string &  longName,
int  valueType,
void *  valuePtr,
const std::string &  helpArgName,
const std::string &  helpText,
bool  showDefault 
)
virtual

Adds an allowed option to the parser.

Parameters
shortNameShort option name, without leading hyphen. If empty, this option does not support short format.
longNameLong option name, without leading hyphens. If empty, this option does not support long format.
valueTypeType of value that this option sets. Must be one of the AppOption::TYPE_* constants.
valuePtrPointer to a variable that holds the option value.
helpArgNameOption argument name to display in the help text.
helpTextOption help text.
showDefaultWhether or not to show the default value of the option in the help text. The default value will be appended to the help text given in helpText.

Definition at line 252 of file App.cpp.

◆ allowUnknownOption()

void allowUnknownOption ( bool  allow = true)

Determines whether or not the parser will allow unknown options to pass through the parser without generating an error.

The default behavior is to disallow unknown options.

Parameters
allowWhether or not to allow unknown options to pass through.

Definition at line 262 of file App.cpp.

◆ parse()

int parse ( int  argc,
char **  argv 
)
virtual

Parses the command-line options.

After parsing, any unparsed arguments are collected in unparsedArgs.

Parameters
argcThe number of arguments specified on the command line, counting the executable name itself.
argvThe list of arguments specified on the command line, including the executable name itself.
Returns
An integer indicating the success or failure of the parsing operation, as follows: 0 = all options parsed successfully 1 = error encountered in option processing 2 = usage information was requested 3 = version information was requested

Definition at line 297 of file App.cpp.

◆ setDescription()

void setDescription ( const std::string &  description)

Sets the portion of the usage information where the application description is displayed.

Parameters
descriptionThe application description.

Definition at line 267 of file App.cpp.

◆ setDisplayWidth()

void setDisplayWidth ( int  displayWidth = 75)

Sets the display width of the usage information.

Parameters
displayWidthThe display width, in characters.

Definition at line 272 of file App.cpp.

◆ setEpilogText()

void setEpilogText ( const std::string &  epilogText)

Sets the epilog portion of the usage information; that is, the part that comes after the list of supported options.

The epilog text may be divided into lines via newline (
) characters.

Parameters
epilogTextThe epilog text.

Definition at line 277 of file App.cpp.

◆ setExecutable()

void setExecutable ( const std::string &  executable)

Sets the portion of the usage information where the executable name is displayed.

This is usually the contents of argv[0].

Parameters
executableThe executable name to display.

Definition at line 282 of file App.cpp.

◆ setUnparsedArgText()

void setUnparsedArgText ( const std::string &  unparsedArgText)

Sets the portion of the usage information that represents the collection of unparsed arguments.

Parameters
unparsedArgTextThe text to display.

Definition at line 287 of file App.cpp.

◆ setVersion()

void setVersion ( const std::string &  version)

Sets the portion of the usage information that represents the application version.

Parameters
versionThe application version.

Definition at line 292 of file App.cpp.


The documentation for this class was generated from the following files: