UI::Util::CmdLine::CmdLine Class Reference

Simple Command Line interface. More...

`#include <CmdLine.hpp>`

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

## 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.
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.
Cmd * | findCmd (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

## CmdLine()

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

  is | In-Stream; use Null-Pointer to run interactive (using libreadline).
  os | Out-Stream.
  es | Error-Out-Stream.
  title | Initial description of the command line (variable __TITLE).
  prompt | Initial prompt (variable __PROMPT).

References add(), es(), HelpCmd, os(), setVar(), and SourceCmd.

Referenced by SourceCmd.

## Member Function Documentation

## add()

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

Add a command to the command line.

Parameters

  cmd | Command to add.

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

Examples
  CmdLine.cpp.

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

Referenced by CmdLine().

## run()

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::ato(), 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:

- CmdLine.hpp
- CmdLine.cpp