c++/parameter-lister/CLI.cpp
author František Kučera <franta-hg@frantovo.cz>
Sun, 03 May 2015 22:00:12 +0200
changeset 7 2f46492e90bc
parent 5 1581a99ab33f
child 9 598a575ae57f
permissions -rw-r--r--
OutputModule and TerminalOutputModule skeletons
     1 #include <cstdlib>
     2 #include <iostream>
     3 #include <vector>
     4 #include <algorithm>
     5 #include <boost/optional.hpp>
     6 
     7 #include "info/globalcode/parameterLister/terminalCodes/TerminalCodes.h"
     8 #include "info/globalcode/parameterLister/OutputModule.h"
     9 #include "info/globalcode/parameterLister/TerminalOutputModule.h"
    10 
    11 using namespace std;
    12 using namespace info::globalcode::parameterLister;
    13 
    14 namespace info {
    15 namespace globalcode {
    16 namespace parameterLister {
    17 
    18 boost::optional<string> getenv(const string name) {
    19 	const char * value = ::getenv(name.c_str());
    20 	if (value == 0) {
    21 		return boost::optional<string>();
    22 	} else {
    23 		return boost::optional<string>(value);
    24 	}
    25 }
    26 
    27 
    28 }
    29 }
    30 }
    31 
    32 int main(int argc, char* argv[]) {
    33 	terminalCodes::Modifier fgGreen(terminalCodes::FG_GREEN);
    34 	terminalCodes::Modifier fgReset(terminalCodes::FG_DEFAULT);
    35 
    36 	cout << "INFO: " << fgGreen << "Parameter lister" << fgReset << " is starting" << endl;
    37 
    38 	string command = argv[0];
    39 	vector<string> args;
    40 
    41 	for (int i = 1; i < argc; i++) {
    42 		args.push_back(argv[i]);
    43 	}
    44 
    45 	for_each(args.begin(), args.end(), [command, fgGreen, fgReset](string s) {
    46 		cout << fgGreen << command << fgReset << ": " << s << endl;
    47 	});
    48 
    49 
    50 	for (int i = 0; i < args.size(); i++) {
    51 		string s = args[i];
    52 		cout << i + 1 << ":" << s.length() << " = \"" << s << "\"" << endl;
    53 	}
    54 
    55 	{
    56 		string envName = args[0];
    57 		boost::optional<string> outputModule = getenv(envName);
    58 
    59 		if (outputModule.is_initialized()) {
    60 			cout << "ENV: " << envName << " = " << outputModule.get();
    61 		} else {
    62 			cout << "ENV: " << envName << " is missing";
    63 		}
    64 	}
    65 	
    66 	{
    67 		OutputModule om;
    68 		TerminalOutputModule tom;
    69 	}
    70 
    71 
    72 	return 0;
    73 }