3 * Copyright © 2015 František Kučera (frantovo.cz)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <boost/optional.hpp>
26 #include "info/globalcode/parameterLister/OutputModule.h"
27 #include "info/globalcode/parameterLister/TerminalOutputModule.h"
30 using namespace info::globalcode::parameterLister;
33 namespace globalcode {
34 namespace parameterLister {
36 const string ENV_BASE = "PARAMETER_LISTER";
37 const string ENV_OUTPUT_MODULE_NAME = ENV_BASE + "_OUTPUT";
39 boost::optional<string> getenv(const string name) {
40 const char * value = ::getenv(name.c_str());
42 return boost::optional<string>();
44 return boost::optional<string>(value);
52 shared_ptr<OutputModule> chooseOutputModule() {
53 boost::optional<string> moduleName = getenv(ENV_OUTPUT_MODULE_NAME);
54 if (moduleName.is_initialized()) {
55 // TODO: use a map instead of sequence of IFs
56 if (moduleName.get() == "terminal") {
57 return shared_ptr<OutputModule>(new TerminalOutputModule());
61 return shared_ptr<OutputModule>(new OutputModule());
64 int main(int argc, char* argv[]) {
67 string command = argv[0];
70 for (int i = 1; i < argc; i++) {
71 args.push_back(argv[i]);
75 shared_ptr<OutputModule> outputModule = chooseOutputModule();
77 return outputModule->process(cout, command, args);