ARC SDK
Public Member Functions
Arc::OptionParser Class Reference

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ OptionParser()

Arc::OptionParser::OptionParser ( const std::string &  arguments = "",
const std::string &  summary = "",
const std::string &  description = "" 
)

Create a new OptionParser.

Parameters
argumentsCommand line arguments
summaryBrief summary of command
descriptionDetailed description of command

Member Function Documentation

◆ AddOption() [1/4]

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.

Parameters
shortOptShort version of this option
longOptLong version of this option
optDescDescription of option
valValue filled during Parse()

◆ AddOption() [2/4]

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.

Parameters
shortOptShort version of this option
longOptLong version of this option
optDescDescription of option
argDescValue of option argument
valValue filled during Parse()

◆ AddOption() [3/4]

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.

Parameters
shortOptShort version of this option
longOptLong version of this option
optDescDescription of option
argDescValue of option argument
valValue filled during Parse()

◆ AddOption() [4/4]

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.

Parameters
shortOptShort version of this option
longOptLong version of this option
optDescDescription of option
argDescValue of option argument
valValue filled during Parse()

◆ DefineOptionsGroup()

void Arc::OptionParser::DefineOptionsGroup ( const std::string  groupID,
const std::string &  groupName 
)

Add an options group.

groupID Options group ID

Parameters
groupNameOptions group Name

◆ GetCommandWithArguments()

const std::string& Arc::OptionParser::GetCommandWithArguments ( ) const
inline

Get command and arguments.

Get the arguments as they were passed to the Parse method as a string joined by spaces.

Returns
The command and all arguments joined by a spaces.
Since
Added in 4.1.0.

◆ GroupAddOption() [1/4]

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.

Parameters
groupIDOptions group ID
shortOptShort version of this option
longOptLong version of this option
optDescDescription of option
valValue filled during Parse()
Since
Added in 6.4.0.

◆ GroupAddOption() [2/4]

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.

Parameters
groupIDOptions group ID
shortOptShort version of this option
longOptLong version of this option
optDescDescription of option
argDescValue of option argument
valValue filled during Parse()
Since
Added in 6.4.0.

◆ GroupAddOption() [3/4]

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.

Parameters
groupIDOptions group ID
shortOptShort version of this option
longOptLong version of this option
optDescDescription of option
argDescValue of option argument
valValue filled during Parse()
Since
Added in 6.4.0.

◆ GroupAddOption() [4/4]

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.

Parameters
groupIDOptions group ID
shortOptShort version of this option
longOptLong version of this option
optDescDescription of option
argDescValue of option argument
valValue filled during Parse()
Since
Added in 6.4.0.

◆ 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.

Returns
The list of command line arguments

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