![]() |
cppassist
1.0.0.f4fab4f962ff
C++ sanctuary for small but powerful and frequently required, stand alone features.
|
Command line action. More...
#include <cppassist/include/cppassist/cmdline/CommandLineAction.h>
Public Member Functions | |
CommandLineAction (const std::string &name="", const std::string &description="") | |
Constructor. More... | |
virtual | ~CommandLineAction () |
Destructor. More... | |
const std::string & | name () const |
Get action name. More... | |
void | setName (const std::string &name) |
Set action name. More... | |
const std::string & | description () const |
Get description. More... | |
void | setDescription (const std::string &description) |
Set description. More... | |
const std::vector< CommandLineCommand * > & | commands () const |
Get commands. More... | |
CommandLineCommand * | getCommand (const std::string &name) const |
Get command by name. More... | |
void | add (CommandLineCommand *command) |
Add command. More... | |
const std::vector< CommandLineOption * > & | options () const |
Get options. More... | |
CommandLineOption * | getOption (const std::string &name) const |
Get option by name. More... | |
void | add (CommandLineOption *option) |
Add option. More... | |
const std::vector< CommandLineSwitch * > & | switches () const |
Get switches. More... | |
CommandLineSwitch * | getSwitch (const std::string &name) const |
Get switch by name. More... | |
void | add (CommandLineSwitch *sw) |
Add switch. More... | |
const std::vector< CommandLineParameter * > & | parameters () const |
Get parameters. More... | |
CommandLineParameter * | getParameter (const std::string &name) const |
Get parameter by name. More... | |
CommandLineParameter * | getParameter (size_t index) const |
Get parameter by index. More... | |
void | add (CommandLineParameter *parameter) |
Add parameter. More... | |
bool | optionalParametersAllowed () const |
Check if optional parameters are allowed by the action. More... | |
void | setOptionalParametersAllowed (bool allowed) |
Set if optional parameters are allowed by the action. More... | |
const std::string & | optionalParameterName () const |
Get optional parameter name. More... | |
void | setOptionalParameterName (const std::string &name) |
Set optional parameter name. More... | |
std::string | usage () const |
Get usage text. More... | |
void | reset () |
Reset state (forget all information from previous parsings) More... | |
void | parse (int argc, char *argv[]) |
Parse command line. More... | |
bool | hasErrors () const |
Check if there were any errors during parsing. More... | |
const std::vector< std::string > & | errors () const |
Get errors. More... | |
bool | activated () const |
Check if action has been activated. More... | |
const std::vector< std::string > & | optionalParameters () const |
Get optional parameters specified on the command line. More... | |
virtual int | execute () |
Execute action. More... | |
Protected Member Functions | |
bool | checkActivated () |
Check if this action has been activated. More... | |
void | checkErrors () |
Checks for errors and collects error messages. More... | |
Protected Attributes | |
std::string | m_name |
Action name. More... | |
std::string | m_description |
Description text. More... | |
std::vector< CommandLineCommand * > | m_commands |
List of commands. More... | |
std::vector< CommandLineOption * > | m_options |
List of options. More... | |
std::vector< CommandLineSwitch * > | m_switches |
List of switches. More... | |
std::vector< CommandLineParameter * > | m_parameters |
List of parameters. More... | |
bool | m_optionalParametersAllowed |
true if optional parameters are allowed, else false More... | |
std::string | m_optionalParameterName |
Name for optional parameters. More... | |
bool | m_activated |
true if activated, else false More... | |
std::vector< std::string > | m_optionalParameters |
List of optional parameters. More... | |
std::vector< std::string > | m_errors |
List of parsing errors. More... | |
Command line action.
Specifies an action that can be invoked on the command line. An action is defined by a set of items (commands, options, switches, and parameters), which may be present on the command line. If all non-optional commands, switches, and options are found, the action is invoked.
Example: myapp list <category> [<type>] [--show-details]
cppassist::CommandLineAction::CommandLineAction | ( | const std::string & | name = "" , |
const std::string & | description = "" |
||
) |
Constructor.
[in] | name | Program name |
[in] | description | Description text |
|
virtual |
Destructor.
const std::string& cppassist::CommandLineAction::name | ( | ) | const |
Get action name.
void cppassist::CommandLineAction::setName | ( | const std::string & | name | ) |
Set action name.
[in] | name | Action name |
const std::string& cppassist::CommandLineAction::description | ( | ) | const |
Get description.
void cppassist::CommandLineAction::setDescription | ( | const std::string & | description | ) |
Set description.
[in] | description | Description text |
const std::vector<CommandLineCommand *>& cppassist::CommandLineAction::commands | ( | ) | const |
Get commands.
CommandLineCommand* cppassist::CommandLineAction::getCommand | ( | const std::string & | name | ) | const |
Get command by name.
[in] | name | Command name |
void cppassist::CommandLineAction::add | ( | CommandLineCommand * | command | ) |
Add command.
[in] | command | Command line command (must NOT be null!) |
const std::vector<CommandLineOption *>& cppassist::CommandLineAction::options | ( | ) | const |
Get options.
CommandLineOption* cppassist::CommandLineAction::getOption | ( | const std::string & | name | ) | const |
Get option by name.
[in] | name | Option name |
void cppassist::CommandLineAction::add | ( | CommandLineOption * | option | ) |
Add option.
[in] | option | Command line option (must NOT be null!) |
const std::vector<CommandLineSwitch *>& cppassist::CommandLineAction::switches | ( | ) | const |
Get switches.
CommandLineSwitch* cppassist::CommandLineAction::getSwitch | ( | const std::string & | name | ) | const |
Get switch by name.
[in] | name | Switch name |
void cppassist::CommandLineAction::add | ( | CommandLineSwitch * | sw | ) |
Add switch.
[in] | sw | Command line switch (must NOT be null!) |
const std::vector<CommandLineParameter *>& cppassist::CommandLineAction::parameters | ( | ) | const |
Get parameters.
CommandLineParameter* cppassist::CommandLineAction::getParameter | ( | const std::string & | name | ) | const |
Get parameter by name.
[in] | name | Parameter name |
CommandLineParameter* cppassist::CommandLineAction::getParameter | ( | size_t | index | ) | const |
Get parameter by index.
[in] | index | Parameter index |
void cppassist::CommandLineAction::add | ( | CommandLineParameter * | parameter | ) |
Add parameter.
[in] | parameter | Command line parameter (must NOT be null!) |
bool cppassist::CommandLineAction::optionalParametersAllowed | ( | ) | const |
Check if optional parameters are allowed by the action.
true
if optional parameters are allowed, else false
void cppassist::CommandLineAction::setOptionalParametersAllowed | ( | bool | allowed | ) |
Set if optional parameters are allowed by the action.
[in] | allowed | true if optional parameters are allowed, else false |
const std::string& cppassist::CommandLineAction::optionalParameterName | ( | ) | const |
Get optional parameter name.
void cppassist::CommandLineAction::setOptionalParameterName | ( | const std::string & | name | ) |
Set optional parameter name.
[in] | name | Parameter name (e.g., "path") |
std::string cppassist::CommandLineAction::usage | ( | ) | const |
Get usage text.
void cppassist::CommandLineAction::reset | ( | ) |
Reset state (forget all information from previous parsings)
void cppassist::CommandLineAction::parse | ( | int | argc, |
char * | argv[] | ||
) |
Parse command line.
[in] | argc | Number of arguments |
[in] | argv | List of arguments |
bool cppassist::CommandLineAction::hasErrors | ( | ) | const |
Check if there were any errors during parsing.
true
if errors have been found, else false
const std::vector<std::string>& cppassist::CommandLineAction::errors | ( | ) | const |
Get errors.
bool cppassist::CommandLineAction::activated | ( | ) | const |
Check if action has been activated.
true
if activated, else false
const std::vector<std::string>& cppassist::CommandLineAction::optionalParameters | ( | ) | const |
Get optional parameters specified on the command line.
|
virtual |
Execute action.
|
protected |
Check if this action has been activated.
true
if activated, else false
|
protected |
Checks for errors and collects error messages.
|
protected |
Action name.
|
protected |
Description text.
|
protected |
List of commands.
|
protected |
List of options.
|
protected |
List of switches.
|
protected |
List of parameters.
|
protected |
true
if optional parameters are allowed, else false
|
protected |
Name for optional parameters.
|
protected |
true
if activated, else false
|
protected |
List of optional parameters.
|
protected |
List of parsing errors.