41#include "drain/util/BeanLike.h"
42#include "drain/util/Flags.h"
43#include "drain/util/ReferenceMap.h"
44#include "drain/util/VariableMap.h"
64 Command(
const Command & cmd) : section(cmd.section), lastParameters(cmd.lastParameters){
80 const std::string & getDescription()
const = 0;
97 std::stringstream sstr;
99 for (
const auto & entry: args){
100 parameters[entry.first] = entry.second;
106 sstr << entry.first <<
'=' << entry.second;
108 lastParameters = sstr.str();
119 getParameters()[key] = value;
120 std::stringstream sstr;
121 sstr << key <<
'=' << value;
122 lastParameters = sstr.str();
130 bool hasParameters()
const {
132 Logger mout(__FILE__, __FUNCTION__);
137 const ReferenceMap::const_iterator it = params.begin();
138 if (it == params.end())
141 return it->second.getType() !=
typeid(void);
159 void run(
const std::string & params =
"") final {
192 const std::string & getLastParameters()
const {
193 return lastParameters;
198 void help(std::ostream & ostr = std::cout,
bool DETAILED=
false)
const;
201 void getRelatedCommands(std::ostream & ostr = std::cout)
const;
222 relatedCommands.insert(cmdKey);
229 std::set<std::string> relatedCommands;
244 std::string lastParameters;
249std::ostream & operator<<(std::ostream & ostr,
const Command &cmd){
250 ostr << cmd.getName();
251 if (cmd.hasParameters()){
252 ostr <<
' ' << cmd.getParameters();
313template <
class B,
class B2=B>
322 BeanCommand(
const std::string & name,
const std::string & description) : bean(name, description){
341 const bean_t & getBean()
const {
355 return getBean().getName();
359 const std::string & getDescription() const final {
360 return getBean().getDescription();
365 return getBean().getParameters();
372 return getBean().getParameters();
433 BasicCommand(
const std::string & name,
const std::string & description);
452template <
class T = std::
string>
459 SimpleCommand(
const std::string & name,
const std::string & description,
460 const std::string & key=
"value",
const T & initValue = T(),
const std::string & unit =
"") :
BasicCommand(name, description) {
463 getParameters().link(key, value = initValue, unit);
466 Context & ctx = getContext<Context>();
468 mout.
warn(
"Empty value key in command ", name,
" (", description,
")");
477 const std::string & key, std::initializer_list<S> l ,
const std::string & unit =
"") :
BasicCommand(name, description) {
480 getParameters().link(key, value);
483 Context & ctx = getContext<Context>();
485 mout.
warn(
"Empty value key in command ", name,
" (", description,
")");
492 getParameters().
copyStruct(cmd.getParameters(), cmd, *
this);
Simple implementation of Command: adds name , description and parameters .
Definition Command.h:429
Retrieves bean dynamically for each call.
Definition Command.h:314
const std::string & getName() const final
Returns the class name of this command, like "CmdVerbose".
Definition Command.h:354
Base class for commands: typically actions taking parameters but also plain variable assignments and ...
Definition Command.h:55
int cmd_section_type
Definition Command.h:182
void linkRelated(const std::string &cmdKey) const
Add related command(s), to appear in help after "See-also:" phrase.
Definition Command.h:221
virtual const std::string & getName() const =0
Returns the class name of this command, like "CmdVerbose".
virtual void run(const std::string ¶ms="") final
Description of result, comparable to a return type of a function. ?
Definition Command.h:159
virtual void exec() const
Run the command with current parameter values.
Definition Command.h:175
void setParameter(const std::string &key, const T &value)
Set a value to a single parameter.
Definition Command.h:118
virtual void setParameters(const std::string &args) final
Definition Command.cpp:40
virtual void update()
Optional method for preparing command to execution.
Definition Command.h:170
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:312
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:430
Definition ReferenceMap.h:207
void copyStruct(const ReferenceMap &m, const T &src, T &dst, extLinkPolicy policy=RESERVE)
Experimental. Copies references and values of a structure to another.
Definition ReferenceMap.h:399
A single-parameter command.
Definition Command.h:453
SimpleCommand(const std::string &name, const std::string &description, const std::string &key, std::initializer_list< S > l, const std::string &unit="")
Constuctor designer for SimpleCommand<Unituple<> > .
Definition Command.h:476
char separator
Default character used for splitting input and output. See setValues.
Definition SmartMap.h:85
Definition DataSelector.cpp:1277
Definition Sprinter.h:137