CLI for C++ Project Page CLI for C++ Home Page

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

CLI::Option Class Reference

Describes a single command-line option. More...

#include <Option.h>

List of all members.

Public Types

enum  Args { NO_ARGS, ONE_ARG, AT_LEAST_ONE_ARG, MANY_ARGS }
 Enumeration to specify how many arguments this option can take. More...

Public Member Functions

 Option ()
 Option (const Option &)
Optionoperator= (const Option &)
 Option (const char *const option, const bool hasArg, const char *const description)
 Construct an option from the given parameters.
 Option (const char *const option, const Args takesArgs, const char *const description)
 Construct an option from the given parameters.
 Option (const char *const option, const char *const description)
 Construct an option from the given parameters.
 Option (const char *const option, const char *const longOption, const bool hasArg, const char *const description)
 Construct an option from the given parameters.
 Option (const char *const option, const char *const longOption, const Args takesArgs, const char *const description)
 Construct an option from the given parameters.
 ~Option ()
std::string getArgName () const
 Provide the display name used for the argument to this option.
std::string getOpt () const
 Return a copy of the short option.
std::string getLongOpt () const
 Return a copy of the long option.
bool hasLongOpt () const
 Report whether the option has a long option.
std::string getDescription () const
 Return the description for this option as would be presented in a help screen.
int getId () const
 Returns an identifier for this option.
std::string getValue () const
 Get the value for this option.
std::string getValue (const char *const defaultValue) const
 Get the value for this option.
std::string getValue (const unsigned index) const
 Get an argument value for this option at the given index location.
std::vector< std::string > getValues () const
bool hasArgName () const
 Report whether the arg name value for this option was set.
bool hasArg () const
bool hasArgs () const
void setArgName (const std::string &argName)
 Set the argument name used by this option as used in help screens.
void setArgs (const Args takesArgs)
 Specify how many arguments this option can take.
void addValue (const std::string &value)
 Add a value to this option.


Detailed Description

Describes a single command-line option.

Author:
John Poplett
See also:
Options, CommandLine


Member Enumeration Documentation

enum CLI::Option::Args
 

Enumeration to specify how many arguments this option can take.

An option can have either no arguments, exactly one argument, one or more arguments, or zero or more arguments.

Enumerator:
NO_ARGS 
ONE_ARG 
AT_LEAST_ONE_ARG 
MANY_ARGS 


Constructor & Destructor Documentation

CLI::Option::Option  ) 
 

CLI::Option::Option const Option  ) 
 

CLI::Option::Option const char *const   option,
const bool  hasArg,
const char *const   description
 

Construct an option from the given parameters.

Parameters:
option short option
hasArg true if option takes a single argument
description textual description for user help

CLI::Option::Option const char *const   option,
const Args  takesArgs,
const char *const   description
 

Construct an option from the given parameters.

Parameters:
option short option
takesArgs specify number of allowable arguments for this option
description textual description for user help

CLI::Option::Option const char *const   option,
const char *const   description
 

Construct an option from the given parameters.

This constructor assumes that the option does not take an argument.

Parameters:
option short option
description textual description for user help

CLI::Option::Option const char *const   option,
const char *const   longOption,
const bool  hasArg,
const char *const   description
 

Construct an option from the given parameters.

Parameters:
option short option (e.g. "-c")
longOption long option (e.g. of the form "--something")
hasArg true if option takes a single argument
description textual description for user help

CLI::Option::Option const char *const   option,
const char *const   longOption,
const Args  takesArgs,
const char *const   description
 

Construct an option from the given parameters.

Parameters:
option short option (e.g. "-c")
longOption long option (e.g. of the form "--something")
takesArgs specify number of allowable arguments for this option
description textual description for user help

CLI::Option::~Option  ) 
 


Member Function Documentation

void CLI::Option::addValue const std::string &  value  ) 
 

Add a value to this option.

This method is used during parsing or for test purposes.

std::string CLI::Option::getArgName  )  const
 

Provide the display name used for the argument to this option.

This value is used in formatting display help.

std::string CLI::Option::getDescription  )  const
 

Return the description for this option as would be presented in a help screen.

Returns:
the description of this option
See also:
HelpFormatter

int CLI::Option::getId  )  const
 

Returns an identifier for this option.

The value returned must differ from all other active Option instances.

Returns:
this option's identifier

std::string CLI::Option::getLongOpt  )  const
 

Return a copy of the long option.

std::string CLI::Option::getOpt  )  const
 

Return a copy of the short option.

std::string CLI::Option::getValue const unsigned  index  )  const
 

Get an argument value for this option at the given index location.

Parameters:
index address of the given argument value

std::string CLI::Option::getValue const char *const   defaultValue  )  const
 

Get the value for this option.

If none was specified, return the value specified.

Parameters:
defaultValue return this value if an argument is not given.

std::string CLI::Option::getValue  )  const
 

Get the value for this option.

Typically, assumes hasArg() == true.

std::vector<std::string> CLI::Option::getValues  )  const
 

bool CLI::Option::hasArg  )  const
 

bool CLI::Option::hasArgName  )  const
 

Report whether the arg name value for this option was set.

bool CLI::Option::hasArgs  )  const
 

bool CLI::Option::hasLongOpt  )  const
 

Report whether the option has a long option.

Option& CLI::Option::operator= const Option  ) 
 

void CLI::Option::setArgName const std::string &  argName  ) 
 

Set the argument name used by this option as used in help screens.

The default value otherwise is "arg".

See also:
HelpFormatter

void CLI::Option::setArgs const Args  takesArgs  ) 
 

Specify how many arguments this option can take.

Parameters:
takesArgs specify the number of valid arguments for this option
See also:
Args


The documentation for this class was generated from the following file:
SourceForge Logo hosts this site. Send comments to:
John Poplett