ui-utilcpp  1.8.5
Public Member Functions | Protected Member Functions | Friends
UI::Util::CmdLine::CmdLine Class Reference

Simple Command Line interface. More...

#include <CmdLine.hpp>

Collaboration diagram for UI::Util::CmdLine::CmdLine:
Collaboration graph

Public Member Functions

 CmdLine (std::istream *is=&std::cin, std::ostream *os=&std::cout, std::ostream *es=&std::cerr, std::string const &title="Simple Command Line Interface", std::string const &prompt="\nCommand # ")
 
void add (Cmd *cmd)
 Add a command to the command line. More...
 
std::string getVar (std::string const &key) const
 Get variable value.
 
void setVar (std::string const &key, std::string const &value)
 Set variable value.
 
void showVar (std::string const &key)
 Show (print) variable value.
 
void showVar (std::map< std::string, std::string >::iterator i)
 Show (print) variable values.
 
void showVars ()
 Show (print) all variable values.
 
std::ostream & os ()
 Get out-stream.
 
std::ostream & es ()
 Get in-stream.
 
CmdfindCmd (std::string const &name) const
 Find a command from name.
 
int run ()
 

Protected Member Functions

std::string readLine (std::string const &promptVar="__PROMPT")
 Only source for input.
 

Friends

class HelpCmd
 These two need access to CmdLine variables – might be better to encapsulate further ;).
 
class SourceCmd
 These two need access to CmdLine variables – might be better to encapsulate further ;).
 

Detailed Description

Simple Command Line interface.

Short howto: Write your own command line class, inherit from CmdLine, inherit custom command classes from Cmd (overwrite private run function). Use run() to start the interface.

When run interactively, libreadline is used.

This class defines some common commands that cannot be used as custom commands later.

Examples:
CmdLine.cpp.

Constructor & Destructor Documentation

UI::Util::CmdLine::CmdLine::CmdLine ( std::istream *  is = &std::cin,
std::ostream *  os = &std::cout,
std::ostream *  es = &std::cerr,
std::string const &  title = "Simple Command Line Interface",
std::string const &  prompt = "\nCommand # " 
)
Parameters
isIn-Stream; use Null-Pointer to run interactive (using libreadline).
osOut-Stream.
esError-Out-Stream.
titleInitial description of the command line (variable __TITLE).
promptInitial prompt (variable __PROMPT).

References add(), UI::Util::delAnySeqContainer(), HelpCmd, setVar(), and SourceCmd.

Member Function Documentation

void UI::Util::CmdLine::CmdLine::add ( Cmd cmd)

Add a command to the command line.

Parameters
cmdCommand to add.
Note
Command must be created via "new"; will be deleted automatically in CmdLine's destructor.

References UI::Util::CmdLine::Cmd::setCL().

Referenced by CmdLine().

int UI::Util::CmdLine::CmdLine::run ( )
Returns
: 0 if everything was fine (no errors), >0 if there have been # ignored errors, <0 if it returned on error (with __FATAL set to 1). Negative amount of former errors.

References UI::Util::CmdLine::Cmd::commandFromLine(), es(), findCmd(), UI::Util::CmdLine::Cmd::getHelp(), getVar(), os(), UI::Util::CmdLine::Cmd::parse(), readLine(), UI::Util::CmdLine::Cmd::run(), and setVar().


The documentation for this class was generated from the following files: