class AbstractCommand

File Information

Library: OSP/Shell
Package: Shell
Header: Poco/OSP/Shell/AbstractCommand.h


AbstractCommand provides a partial implementation of Command, doing automatic argument handling based on the options handling framework from the Util library.

Options must be given in Unix-style syntax (-o or —option).

Option handling for commands works in a similar way to command line options handling in the Poco::Util::Application class.


Direct Base Classes: Command

All Base Classes: Command

Known Derived Classes: OSPCommand, LoginCommand, QuitCommand

Member Summary

Member Functions: commandName, defineOptions, displayHelp, execute, executeImpl, handleHelp, handleOption, options, processOptions, stopOptionsProcessing

Inherited Functions: execute


AbstractCommand protected


Creates the AbstractCommand.

AbstractCommand protected

    const std::string & description,
    const std::string & usage

Creates the AbstractCommand, using the given description and usage hint.

The given description and usage hint is used in the help text given if the command is invoked with the —help option.


~AbstractCommand protected virtual

virtual ~AbstractCommand();

Destroys the AbstractCommand.

Member Functions

execute virtual

virtual int execute(
    Session & session,
    const std::vector < std::string > & args,
    std::ostream & ostr

commandName protected inline

const std::string & commandName() const;

Returns the command name.

defineOptions protected virtual

virtual void defineOptions(
    Poco::Util::OptionSet & options

Called before command line processing begins. If a Command wants to support command line arguments, it must override this method and call the base class implementation as well.

The default implementation only defines the —help option.

A Command should specify a callback to handle the option.

displayHelp protected

void displayHelp(
    std::ostream & ostr

Writes a help text to the given stream.

executeImpl protected virtual

virtual int executeImpl(
    Session & session,
    const std::vector < std::string > & args,
    std::ostream & ostr
) = 0;

Execute the command, using the given arguments. Called by AbstractCommand::execute() after options have been handled.

Any output produced by executing the command can be written to the given output stream.

An integer must be returned that denotes success or failure of the command. Upon success, 0 shall be returned. The CommandStatus enumeration defines a few commonly used error codes that should be used.

handleHelp protected

void handleHelp(
    const std::string & name,
    const std::string & value

Handles the —help command line option.

handleOption protected virtual

virtual void handleOption(
    const std::string & name,
    const std::string & value

Called when the option with the given name is encountered during command line arguments processing.

The default implementation does option validation, bindings and callback handling.

Overriding implementations must call the base class implementation.

options protected inline

const Poco::Util::OptionSet & options() const;

Returns the application's option set.

processOptions protected

void processOptions(
    std::vector < std::string > & args

Processes command-line options.

stopOptionsProcessing protected

void stopOptionsProcessing();

If called from an option callback, stops all further options processing.

If called, the following options on the command line will not be processed, and required options will not be checked.

This is useful, for example, if an option for displaying help information has been encountered and no other things besides displaying help shall be done.