ARC SDK
|
Command line option parser used by ARC command line tools. More...
#include <arc/OptionParser.h>
Public Member Functions | |
OptionParser (const std::string &arguments="", const std::string &summary="", const std::string &description="") | |
Create a new OptionParser. More... | |
void | AddOption (const char shortOpt, const std::string &longOpt, const std::string &optDesc, bool &val) |
Add an option which does not take any arguments in default group. More... | |
void | AddOption (const char shortOpt, const std::string &longOpt, const std::string &optDesc, const std::string &argDesc, int &val) |
Add an option which takes an integer argument in default group. More... | |
void | AddOption (const char shortOpt, const std::string &longOpt, const std::string &optDesc, const std::string &argDesc, std::string &val) |
Add an option which takes a string argument in default group. More... | |
void | AddOption (const char shortOpt, const std::string &longOpt, const std::string &optDesc, const std::string &argDesc, std::list< std::string > &val) |
Add an option in default group which takes a string argument and can be specified multiple times. More... | |
void | DefineOptionsGroup (const std::string groupID, const std::string &groupName) |
Add an options group. More... | |
void | GroupAddOption (const std::string groupID, const char shortOpt, const std::string &longOpt, const std::string &optDesc, bool &val) |
Add an option which does not take any arguments to group. More... | |
void | GroupAddOption (const std::string groupID, const char shortOpt, const std::string &longOpt, const std::string &optDesc, const std::string &argDesc, int &val) |
Add an option which takes an integer argument. More... | |
void | GroupAddOption (const std::string groupID, const char shortOpt, const std::string &longOpt, const std::string &optDesc, const std::string &argDesc, std::string &val) |
Add an option which takes a string argument. More... | |
void | GroupAddOption (const std::string groupID, const char shortOpt, const std::string &longOpt, const std::string &optDesc, const std::string &argDesc, std::list< std::string > &val) |
Add an option which takes a string argument and can be specified multiple times. More... | |
std::list< std::string > | Parse (int argc, char **argv) |
Parse the options and arguments. More... | |
const std::string & | GetCommandWithArguments () const |
Get command and arguments. More... | |
Command line option parser used by ARC command line tools.
The command line arguments and a brief and detailed description can be set in the constructor. Each command line option should be added with an AddOption() method, corresponding to the type of the option. Parse() can then be called with the same arguments as main() takes. It returns a list of arguments and fills each "val" passed in AddOption() if the corresponding option is specified on the command line.
A help text is automatically generated and displayed on stdout if a help option (-h or -?) is used on the command line. Note that Parse() calls exit(0) after displaying the help text.
Both short and long format options are supported.
Arc::OptionParser::OptionParser | ( | const std::string & | arguments = "" , |
const std::string & | summary = "" , |
||
const std::string & | description = "" |
||
) |
Create a new OptionParser.
arguments | Command line arguments |
summary | Brief summary of command |
description | Detailed description of command |
void Arc::OptionParser::AddOption | ( | const char | shortOpt, |
const std::string & | longOpt, | ||
const std::string & | optDesc, | ||
bool & | val | ||
) |
Add an option which does not take any arguments in default group.
shortOpt | Short version of this option |
longOpt | Long version of this option |
optDesc | Description of option |
val | Value filled during Parse() |
void Arc::OptionParser::AddOption | ( | const char | shortOpt, |
const std::string & | longOpt, | ||
const std::string & | optDesc, | ||
const std::string & | argDesc, | ||
int & | val | ||
) |
Add an option which takes an integer argument in default group.
shortOpt | Short version of this option |
longOpt | Long version of this option |
optDesc | Description of option |
argDesc | Value of option argument |
val | Value filled during Parse() |
void Arc::OptionParser::AddOption | ( | const char | shortOpt, |
const std::string & | longOpt, | ||
const std::string & | optDesc, | ||
const std::string & | argDesc, | ||
std::string & | val | ||
) |
Add an option which takes a string argument in default group.
shortOpt | Short version of this option |
longOpt | Long version of this option |
optDesc | Description of option |
argDesc | Value of option argument |
val | Value filled during Parse() |
void Arc::OptionParser::AddOption | ( | const char | shortOpt, |
const std::string & | longOpt, | ||
const std::string & | optDesc, | ||
const std::string & | argDesc, | ||
std::list< std::string > & | val | ||
) |
Add an option in default group which takes a string argument and can be specified multiple times.
shortOpt | Short version of this option |
longOpt | Long version of this option |
optDesc | Description of option |
argDesc | Value of option argument |
val | Value filled during Parse() |
void Arc::OptionParser::DefineOptionsGroup | ( | const std::string | groupID, |
const std::string & | groupName | ||
) |
Add an options group.
groupID Options group ID
groupName | Options group Name |
|
inline |
Get command and arguments.
Get the arguments as they were passed to the Parse method as a string joined by spaces.
void Arc::OptionParser::GroupAddOption | ( | const std::string | groupID, |
const char | shortOpt, | ||
const std::string & | longOpt, | ||
const std::string & | optDesc, | ||
bool & | val | ||
) |
Add an option which does not take any arguments to group.
groupID | Options group ID |
shortOpt | Short version of this option |
longOpt | Long version of this option |
optDesc | Description of option |
val | Value filled during Parse() |
void Arc::OptionParser::GroupAddOption | ( | const std::string | groupID, |
const char | shortOpt, | ||
const std::string & | longOpt, | ||
const std::string & | optDesc, | ||
const std::string & | argDesc, | ||
int & | val | ||
) |
Add an option which takes an integer argument.
groupID | Options group ID |
shortOpt | Short version of this option |
longOpt | Long version of this option |
optDesc | Description of option |
argDesc | Value of option argument |
val | Value filled during Parse() |
void Arc::OptionParser::GroupAddOption | ( | const std::string | groupID, |
const char | shortOpt, | ||
const std::string & | longOpt, | ||
const std::string & | optDesc, | ||
const std::string & | argDesc, | ||
std::string & | val | ||
) |
Add an option which takes a string argument.
groupID | Options group ID |
shortOpt | Short version of this option |
longOpt | Long version of this option |
optDesc | Description of option |
argDesc | Value of option argument |
val | Value filled during Parse() |
void Arc::OptionParser::GroupAddOption | ( | const std::string | groupID, |
const char | shortOpt, | ||
const std::string & | longOpt, | ||
const std::string & | optDesc, | ||
const std::string & | argDesc, | ||
std::list< std::string > & | val | ||
) |
Add an option which takes a string argument and can be specified multiple times.
groupID | Options group ID |
shortOpt | Short version of this option |
longOpt | Long version of this option |
optDesc | Description of option |
argDesc | Value of option argument |
val | Value filled during Parse() |
std::list<std::string> Arc::OptionParser::Parse | ( | int | argc, |
char ** | argv | ||
) |
Parse the options and arguments.
Should be called after all options have been added with AddOption(). The parameters can be the same as those taken by main(). Note that if a help option is given this method calls exit(0) after printing help text to stdout.