diff -r 09adb33465e4 -r 65f51abd5fb8 c++/parameter-lister/CLI.cpp --- a/c++/parameter-lister/CLI.cpp Mon May 04 00:34:27 2015 +0200 +++ b/c++/parameter-lister/CLI.cpp Tue May 05 22:19:24 2015 +0200 @@ -1,11 +1,11 @@ #include #include #include +#include #include #include #include -#include "info/globalcode/parameterLister/terminalCodes/TerminalCodes.h" #include "info/globalcode/parameterLister/OutputModule.h" #include "info/globalcode/parameterLister/TerminalOutputModule.h" @@ -16,6 +16,9 @@ namespace globalcode { namespace parameterLister { +const string ENV_BASE = "PARAMETER_LISTER"; +const string ENV_OUTPUT_MODULE_NAME = ENV_BASE + "_OUTPUT"; + boost::optional getenv(const string name) { const char * value = ::getenv(name.c_str()); if (value == 0) { @@ -29,12 +32,21 @@ } } +shared_ptr chooseOutputModule() { + boost::optional moduleName = getenv(ENV_OUTPUT_MODULE_NAME); + if (moduleName.is_initialized()) { + // TODO: use a map instead of sequence of IFs + if (moduleName.get() == "terminal") { + return shared_ptr(new TerminalOutputModule()); + } + } + + return shared_ptr(new OutputModule()); +} + int main(int argc, char* argv[]) { - terminalCodes::Modifier fgGreen(terminalCodes::FG_GREEN); - terminalCodes::Modifier fgReset(terminalCodes::FG_DEFAULT); - cout << "INFO: " << fgGreen << "Parameter lister" << fgReset << " is starting" << endl; - + /** Load arguments */ string command = argv[0]; vector args; @@ -42,28 +54,8 @@ args.push_back(argv[i]); } - /** Load environment variable */ - if (args.size() > 0) { - string envName = args[0]; - boost::optional outputModule = getenv(envName); + /** Do formatting */ + shared_ptr outputModule = chooseOutputModule(); - if (outputModule.is_initialized()) { - cout << "ENV: " << envName << " = " << outputModule.get() << endl; - } else { - cout << "ENV: " << envName << " is missing" << endl; - } - } - - /** Do formatting */ - { - shared_ptr om(new OutputModule()); - shared_ptr tom(new TerminalOutputModule()); - shared_ptr o(new TerminalOutputModule()); - - om->process(cout, command, args); - tom->process(cout, command, args); - o->process(cout, command, args); - } - - return 0; + return outputModule->process(cout, command, args); }