Abstract base class for simple interactive shell commands. More...
#include <InteractiveCommand.h>
Public Member Functions | |
virtual | ~InteractiveCommand () |
Virtual destructor can be overwritten in subclasses. More... | |
void | parse_command_line (const char *line) |
Parses a command line and stores the arguments in m_args. More... | |
bool | matches (const char *line) |
Returns true if the command_text() matches the command line. More... | |
virtual const char * | command_text ()=0 |
Returns the command text (i.e. More... | |
virtual const char ** | usage ()=0 |
Returns the usage string. More... | |
virtual void | run ()=0 |
Runs the command; can access the command line arguments in m_args. More... | |
void | clear_args () |
Clears all arguments. More... | |
void | push_arg (std::string key, std::string value) |
Append another key/value pair to the argument list. More... | |
Protected Member Functions | |
bool | parse_string_literal (const char *str, std::string &text, const char **endptr) |
Helper function to parse a string literal. More... | |
Protected Attributes | |
std::vector< std::pair < std::string, std::string > > | m_args |
The vector with key/value pairs for this command. More... | |
Abstract base class for simple interactive shell commands.
The base class parses the command and runs it. For a usage example see the FsBroker client shell: src/cc/Tools/fsclient/fsclient.cc.
Definition at line 45 of file InteractiveCommand.h.
|
inlinevirtual |
Virtual destructor can be overwritten in subclasses.
Definition at line 48 of file InteractiveCommand.h.
|
inline |
Clears all arguments.
Definition at line 79 of file InteractiveCommand.h.
|
pure virtual |
Returns the command text (i.e.
"length")
Abstract function; needs to be overwritten in a subclass!
|
inline |
Returns true if the command_text() matches the command line.
Definition at line 59 of file InteractiveCommand.h.
void InteractiveCommand::parse_command_line | ( | const char * | line | ) |
Parses a command line and stores the arguments in m_args.
This function will exit() if the command line cannot be parsed.
line | A command line; can contain quoted strings |
Definition at line 40 of file InteractiveCommand.cc.
|
protected |
Helper function to parse a string literal.
Definition at line 96 of file InteractiveCommand.cc.
|
inline |
Append another key/value pair to the argument list.
Definition at line 82 of file InteractiveCommand.h.
|
pure virtual |
Runs the command; can access the command line arguments in m_args.
|
pure virtual |
Returns the usage string.
Abstract function; needs to be overwritten in a subclass!
|
protected |
The vector with key/value pairs for this command.
Definition at line 88 of file InteractiveCommand.h.