35#ifndef COMMAND_BANK_UTILS_H_
36#define COMMAND_BANK_UTILS_H_
41#include "drain/image/Image.h"
42#include "drain/util/JSON.h"
44#include "CommandBank.h"
45#include "CommandSections.h"
74 Context & ctx = getContext<Context>();
75 ctx.log.setVerbosity(value);
78 drain::getLog().setVerbosity(value);
79 drain::image::getImgLog().setVerbosity(value-1);
94 Context & ctx = getContext<Context>();
95 ctx.log.setVerbosity(LOG_DEBUG);
96 drain::getLog().setVerbosity(LOG_DEBUG);
97 drain::image::getImgLog().setVerbosity(LOG_DEBUG);
110 void exec()
const override;
135 void commandsToJSON(
const drain::CommandBank & cmdBank,
const std::string & cmds, drain::JSONtree & dst,
const T & separator){
136 std::list<std::string> cmdList;
138 commandsToJSON(cmdBank, cmdList, dst);
142 void commandsToJSON(
const drain::CommandBank & cmdBank,
const std::list<std::string> & cmds, drain::JSONtree & dst);
146 void commandToJSON(
const drain::Command & cmd, drain::JSONtree & dst);
149 void commandToJSON_old(
const drain::Command & cmd, drain::JSONtree & dst);
152 const std::map<std::string,std::string> &
getVariables();
166 std::ostream & ostr = std::cout;
173 if (!cmdBank.
has(value)){
174 mout.
error(
"no such key: " , value );
178 drain::JSONtree jsonRoot;
180 commandToJSON_old(cmdBank.
get(value), jsonRoot[value]);
217 std::string filename;
259 ctx.expandVariables = !ctx.expandVariables;
316 void exec()
const override;
344 cmd_section_type TRIGGER = drain::Static::get<drain::TriggerSection>().index;
353 mout.
debug(
"Storing script with '" ,
getName() ,
"' ." );
397 if (cmdBank.
has(
"general")){
398 cmdBank.
help(
"general");
437template <
class C=Context>
454 C &ctx = getContext<C>();
460 ifstr.open(value.c_str(), std::ios::in);
462 std::stringstream sstr;
463 sstr << ifstr.rdbuf();
471 ctx.formatStr = sstr.str();
475 mout.
error(getName() ,
": opening file '" , value ,
"' failed." );
494 Context & ctx = getContext<>();
498 mout.
error(
"Command '" , value ,
"' not found." );
bool has(const K &key) const
Check if a cloner is defined for this key.
Definition Bank.h:140
const T & get(const K &key) const
Returns the base instance.
Definition Bank.h:158
Simple implementation of Command: adds name , description and parameters .
Definition Command.h:461
const std::string & getName() const final
Returns the command name.
Definition Command.h:384
Definition CommandBankUtils.h:84
void exec() const
Run the command with current parameter values.
Definition CommandBankUtils.h:93
Load script file and execute the commands immediately using current Context.
Definition CommandBankUtils.h:367
Executes the defined script.
Definition CommandBankUtils.h:336
void exec() const
Run the command with current parameter values.
Definition CommandBankUtils.h:350
Definition CommandBankUtils.h:248
void exec() const
Run the command with current parameter values.
Definition CommandBankUtils.h:257
Definition CommandBankUtils.h:103
void exec() const override
Run the command with current parameter values.
Definition CommandBankUtils.cpp:101
CommandBank-dependent.
Definition CommandBankUtils.h:386
void exec() const
Run the command with current parameter values.
Definition CommandBankUtils.h:395
Explain..
Definition CommandBankUtils.h:125
virtual void exec() const
Run the command with current parameter values.
Definition CommandBankUtils.h:156
static const std::map< std::string, std::string > & getVariables()
Definition CommandBankUtils.cpp:279
Definition CommandBankUtils.h:203
void exec() const
Run the command with current parameter values.
Definition CommandBankUtils.cpp:52
Special command for handling undefined commands.
Definition CommandBankUtils.h:481
void exec() const
Run the command with current parameter values.
Definition CommandBankUtils.h:493
Define a script.
Definition CommandBankUtils.h:298
void exec() const override
Run the command with current parameter values.
Definition CommandBankUtils.cpp:299
Define a script.
Definition CommandBankUtils.h:270
Definition CommandBankUtils.h:230
void exec() const
Run the command with current parameter values.
Definition CommandBankUtils.cpp:73
Definition CommandBankUtils.h:63
void exec() const
Run the command with current parameter values.
Definition CommandBankUtils.h:72
Container and execution tools for commands derived from Command.
Definition CommandBank.h:67
std::string notFoundHandlerCmdKey
If defined, the command - key not getName() - to which all unresolved commands are directed.
Definition CommandBank.h:278
std::string execFileCmd
Command for reading and executing commands from a file in the current (running) context.
Definition CommandBank.h:321
void help(std::ostream &ostr=std::cout)
Basic help dump, displays help commands to proceed.
Definition CommandBank.cpp:949
std::string scriptCmd
Command for storing a routine.
Definition CommandBank.h:290
Base class for commands: typically actions taking parameters but also plain variable assignments and ...
Definition Command.h:53
int cmd_section_type
Definition Command.h:187
cmd_section_type section
Section bitmask; zero means hidden from help.
Definition Command.h:188
std::string formatStr
Definition Context.h:214
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:326
Logger & debug(const TT &... args)
Debug information.
Definition Log.h:676
Logger & error(const TT &... args)
Echoes.
Definition Log.h:426
Logger & unimplemented(const TT &... args)
Feature to be done. Special type of Logger::note().
Definition Log.h:521
A single-parameter command.
Definition Command.h:487
static std::ostream & toStream(std::ostream &ostr, const std::initializer_list< T > &x, const SprinterLayout &layout=defaultLayout)
New (experimental)
Definition Sprinter.h:423
static const SprinterLayout jsonLayout
Resembles JSON structure: {"a":1,"b":22,"c":3}.
Definition Sprinter.h:224
CommandBank & getCommandBank()
Global program command registry. Optional utility.
Definition CommandBank.cpp:52