ui-utilcpp
1.8.5
|
Simple Command Line interface. More...
#include <CmdLine.hpp>
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. | |
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 ;). | |
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.
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 # " |
||
) |
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(), UI::Util::delAnySeqContainer(), HelpCmd, setVar(), and SourceCmd.
void UI::Util::CmdLine::CmdLine::add | ( | Cmd * | cmd | ) |
Add a command to the command line.
cmd | Command to add. |
References UI::Util::CmdLine::Cmd::setCL().
Referenced by CmdLine().
int UI::Util::CmdLine::CmdLine::run | ( | ) |
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().