#include <OptionParser.h>
Public Member Functions | |
OptionParser (const char *progname) | |
Constructor: expects a string containing the name of the calling program. | |
bool | addOption (char sn, const char *ln, const char *hm, bool hasArg=false) |
Add a new option to the list. | |
bool | removeOption (const char *ln) |
Remove an option from the list. | |
int | findOption (const char *ln, bool shortName=false) const |
Find the option in the list. | |
int | addArgument (const char *name, const char *help, bool mandatory=true) |
Add a new argument to the argumet list. | |
void | clearArguments () |
Clear the argument list. | |
bool | parse (int argc, const char **argv, StringMap &opts, ArrayList &args) |
Parse the command line. | |
void | usage () |
Print the usage message. | |
const StringBuffer & | getErrMsg () const |
get error message as a StringBuffer | |
const StringBuffer & | getProgramName () const |
Private Attributes | |
StringBuffer | programName |
The program name, used in the usage page. | |
ArrayList | options |
A list of Option objects, representing the options supported by the program. | |
ArrayList | arguments |
A map of arguments, with the name of the arg and the help message This is used only for the usage page. | |
StringBuffer | errMsg |
error string |
int OptionParser::addArgument | ( | const char * | name, | |
const char * | help, | |||
bool | mandatory = true | |||
) |
Add a new argument to the argumet list.
name | the name of the argument | |
help | an help message true if the option argument is mandatory (default=true) |
bool OptionParser::addOption | ( | char | sn, | |
const char * | ln, | |||
const char * | hm, | |||
bool | hasArg = false | |||
) |
Add a new option to the list.
sn | the short name of the option (one letter) ln the long name of the option | |
hm | an help message (one line) true if the option requires an argument (default=false) |
int OptionParser::findOption | ( | const char * | ln, | |
bool | shortName = false | |||
) | const |
Find the option in the list.
ln | the long name of the option to remove |
bool OptionParser::parse | ( | int | argc, | |
const char ** | argv, | |||
StringMap & | opts, | |||
ArrayList & | args | |||
) |
Parse the command line.
argc | the argc parameter, same as the one of the main() function | |
argv | the argv parameter, same as the one of the main() function | |
OUT | an ArrayList of KeyValuePair containing the options found on the commandline | |
OUT | an ArrayList of StringBuffer containing the other arguments found on the commandline |
bool OptionParser::removeOption | ( | const char * | ln | ) |
Remove an option from the list.
ln | the long name of the option to remove |
ArrayList OptionParser::arguments [private] |
A map of arguments, with the name of the arg and the help message This is used only for the usage page.
The arguments are positional and there is no syntax checking on them.
StringBuffer OptionParser::programName [private] |
The program name, used in the usage page.