Library: OSP/Shell
Package: Shell
Header: Poco/OSP/Shell/CommandProcessor.h
The CommandProcessor parses command lines and invokes commands.
Member Functions: addCommand, aliases, context, createCommand, execute, listCommands, parseCommandLine, removeBundle, removeCommand
typedef Poco::SharedPtr < CommandFactory > FactoryPtr;
CommandProcessor(
Poco::OSP::BundleContext::Ptr pContext
);
Creates the CommandProcessor, using the given bundle context.
~CommandProcessor();
Destroys the CommandProcessor.
void addCommand(
const std::string & command,
const std::set < std::string > & aliases,
FactoryPtr pFactory,
const std::string & permission
);
Adds a command to the command processor.
The given command name must be unique, otherwise an ExistsException will be thrown. The given aliases set can be empty. Upon execution of the command, the given permission is checked against the current user's permissions. It can be empty to disable the check.
void aliases(
const std::string & command,
std::set < std::string > & aliases
) const;
Fills the given set with all aliases for the given command.
Poco::OSP::BundleContext::Ptr context() const;
Returns the BundleContext used by the CommandProcessor.
int execute(
Session & session,
const std::string & commandLine,
std::ostream & ostr
);
Executes the command given in commandLine in the given session.
Throws a Poco::NotFoundException if the given command is not known.
The following commands are builtin:
void listCommands(
std::vector < std::string > & commands
) const;
Fills the given vector with the names of all registered commands.
void removeBundle(
Poco::OSP::Bundle::Ptr pBundle
);
Removes all commands defined by the given bundle.
void removeCommand(
const std::string & command
);
Removes the given command.
Command * createCommand(
const Session & session,
const std::string & command
);
Creates a Command object for the given command name.
Throws a Poco::NotFoundException if the given command is unknown. Returns a new command object, or a null pointer if the user is not authorized to call the command.
void parseCommandLine(
const std::string & commandLine,
std::vector < std::string > & items
);
Parses the command line into single items.
The first item is used as command name. Remaining items are arguments to the command. Items are separated by one or more space or tab characters. An item can be enclosed in single or double quotes. Characters can be escaped with a backslash.
static const std::string COMMAND_HELP;
static const std::string COMMAND_LOGIN;
static const std::string COMMAND_QUIT;