Ookii.CommandLine for C++
1.0.0
|
Abstract base class for all shell commands. More...
#include <ookii/shell_command.h>
Public Types | |
using | builder_type = basic_parser_builder< CharType, Traits, Alloc > |
The concrete type of basic_parser_builder used. | |
Public Member Functions | |
basic_shell_command ()=default | |
Initializes a new instance of the basic_shell_command class. | |
basic_shell_command (builder_type &) | |
Initializes a new instance of the basic_shell_command class. More... | |
virtual | ~basic_shell_command ()=default |
Default destructor. | |
virtual int | run ()=0 |
Runs the command, after argument parsing was successful. More... | |
Abstract base class for all shell commands.
When you implement a shell command, you must derive from the basic_shell_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_shell_command_manager.
To specify a name or description for your command, you can either pass them to basic_shell_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 shell command class.
For example:
Several typedefs for common character types are provided:
Type | Definition |
---|---|
ookii::shell_command | ookii::basic_shell_command<char> |
ookii::wshell_command | ookii::basic_shell_command<wchar_t> |
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> . |
|
inline |
Initializes a new instance of the basic_shell_command class.
New-ShellCommand.ps1
can generate code that supports shell commands with a base class that does have a constructor.
|
pure virtual |
Runs the command, after argument parsing was successful.