Ookii.CommandLine for C++
2.0.0
|
Abstract base class for all subcommands. More...
#include <ookii/subcommand.h>
Public Types | |
using | builder_type = basic_parser_builder< CharType, Traits, Alloc > |
The concrete type of basic_parser_builder used. | |
Public Member Functions | |
basic_command ()=default | |
Initializes a new instance of the basic_command class. | |
basic_command (builder_type &) | |
Initializes a new instance of the basic_command class. More... | |
virtual | ~basic_command ()=default |
Default destructor. | |
virtual int | run ()=0 |
Runs the command, after argument parsing was successful. More... | |
Abstract base class for all subcommands.
CharType | The character type used for arguments and other strings. |
Traits | The character traits to use for strings. Defaults to std::char_traits<CharType> . |
Alloc | The allocator to use for strings. Defaults to std::allocator<CharType> . |
When you implement a subcommand, you must derive from the basic_command class, and implement the run() method.
In addition, you must provide a constructor that takes a reference to builder_type, which is a typedef for basic_parser_builder, which creates the arguments accepted by this command. This basic_parser_builder will have been initialized with the name and description of the command, as well as basic_parser_builder::case_sensitive() and basic_parser_builder::locale() values matching the basic_command_manager.
To specify a name or description for your command, you can either pass them to basic_command_manager::add_command(), or you can provide static methods that return them. If a name is not provided using either method, the name will match the type name of the subcommand class.
For example:
Several typedefs for common character types are provided:
Type | Definition |
---|---|
ookii::command | ookii::basic_command<char> |
ookii::wcommand | ookii::basic_command<wchar_t> |
|
inline |
Initializes a new instance of the basic_command class.
New-Subcommand.ps1
can generate code that supports subcommands with a base class that does have a constructor.
|
pure virtual |
Runs the command, after argument parsing was successful.