Command line program.
More...
#include <cppassist/include/cppassist/cmdline/CommandLineProgram.h>
Command line program.
This class can be used to define the logic of a command line program.
◆ CommandLineProgram()
cppassist::CommandLineProgram::CommandLineProgram |
( |
const std::string & |
name = "" , |
|
|
const std::string & |
shortDesc = "" , |
|
|
const std::string & |
description = "" |
|
) |
| |
Constructor.
- Parameters
-
[in] | name | Program name |
[in] | shortDesc | Short description (e.g., version and license) |
[in] | description | Description text |
◆ ~CommandLineProgram()
virtual cppassist::CommandLineProgram::~CommandLineProgram |
( |
| ) |
|
|
virtual |
◆ name()
const std::string& cppassist::CommandLineProgram::name |
( |
| ) |
const |
Get program name.
- Returns
- Program name
◆ setName()
void cppassist::CommandLineProgram::setName |
( |
const std::string & |
name | ) |
|
Set program name.
- Parameters
-
◆ shortDesc()
const std::string& cppassist::CommandLineProgram::shortDesc |
( |
| ) |
const |
Get short description.
- Returns
- Short description (e.g., version and license)
◆ setShortDesc()
void cppassist::CommandLineProgram::setShortDesc |
( |
const std::string & |
shortDesc | ) |
|
Set short description.
- Parameters
-
[in] | shortDesc | Short description (e.g., version and license) |
◆ description()
const std::string& cppassist::CommandLineProgram::description |
( |
| ) |
const |
Get description.
- Returns
- Description text
◆ setDescription()
void cppassist::CommandLineProgram::setDescription |
( |
const std::string & |
description | ) |
|
Set description.
- Parameters
-
[in] | description | Description text |
◆ actions()
const std::vector<CommandLineAction *>& cppassist::CommandLineProgram::actions |
( |
| ) |
const |
Get actions.
- Returns
- List of actions
◆ getAction()
CommandLineAction* cppassist::CommandLineProgram::getAction |
( |
const std::string & |
name | ) |
const |
Get action by name.
- Parameters
-
- Returns
- Pointer to action, null on error
◆ add()
Add action.
- Parameters
-
[in] | action | Command line action (must NOT be null!) |
◆ help()
virtual std::string cppassist::CommandLineProgram::help |
( |
CommandLineAction * |
forAction = nullptr | ) |
const |
|
virtual |
Get help text.
- Parameters
-
[in] | forAction | Action for which help is requested, null for all actions |
- Returns
- Help text
◆ print()
virtual void cppassist::CommandLineProgram::print |
( |
const std::string & |
msg | ) |
|
|
virtual |
Print message.
- Parameters
-
◆ reset()
void cppassist::CommandLineProgram::reset |
( |
| ) |
|
Reset state (forget all information from previous parsings)
◆ parse()
void cppassist::CommandLineProgram::parse |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
Parse command line.
- Parameters
-
[in] | argc | Number of arguments |
[in] | argv | List of arguments |
◆ execute()
int cppassist::CommandLineProgram::execute |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
Execute command line program.
This function parses the command line and executes the selected action. If no action was selected or there were parsing error, the help text is displayed and and error code (1) is returned.
- Parameters
-
[in] | argc | Number of arguments |
[in] | argv | List of arguments |
- Returns
- Error code (0 on success)
◆ executeAction()
virtual int cppassist::CommandLineProgram::executeAction |
( |
CommandLineAction * |
action | ) |
|
|
virtual |
Execute command line action.
This function is called from execute(), when an action has been identified. Override this function to insert code that shall allways be executed (when no error has occured), regardless of the selected action. For example, a program can apply its global options here. Afterwards, the function is expected to call the specified action and return its error code.
- Parameters
-
[in] | action | Command line action to execute |
- Returns
- Error code (0 on success)
◆ hasErrors()
bool cppassist::CommandLineProgram::hasErrors |
( |
| ) |
const |
Check if there were any errors during parsing.
- Returns
true
if errors have been found, else false
◆ selectedAction()
Get action that has been selected.
- Returns
- Action, can be null
◆ m_name
std::string cppassist::CommandLineProgram::m_name |
|
protected |
◆ m_shortDesc
std::string cppassist::CommandLineProgram::m_shortDesc |
|
protected |
Short description (e.g., version and license)
◆ m_description
std::string cppassist::CommandLineProgram::m_description |
|
protected |
◆ m_actions
List of registered actions.
◆ m_selectedAction
Action that has been selected (can be null)
The documentation for this class was generated from the following file: