src/CLIParser.h
branchv_0
changeset 12 7977c1bdba1f
parent 6 4062b8436838
child 13 c9fece435aa2
--- a/src/CLIParser.h	Sun Feb 03 21:53:10 2019 +0100
+++ b/src/CLIParser.h	Tue Feb 05 00:06:44 2019 +0100
@@ -32,7 +32,7 @@
 class CLIParser {
 private:
 
-	// TODO: move common methods/classes to relpipe-lib-cli
+	// FIXME: move common methods/classes to relpipe-lib-cli or relpipe-lib-helper
 
 	string_t readNext(std::vector<string_t> arguments, int& i) {
 		if (i < arguments.size()) return arguments[i++];
@@ -52,9 +52,18 @@
 		else throw relpipe::cli::RelpipeCLIException(L"Unable to parse boolean value of option: " + optionName + L" (expecting true or false)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
 	}
 
+	relpipe::writer::TypeId parseTypeId(const string_t& value) {
+		using t = relpipe::writer::TypeId;
+		if (value == L"string") return t::STRING;
+		else if (value == L"integer") return t::INTEGER;
+		else if (value == L"boolean") return t::BOOLEAN;
+		else throw relpipe::cli::RelpipeCLIException(L"Unable to parse TypeId: " + value, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
+	}
+
 public:
 
 	static const string_t OPTION_RELATION;
+	static const string_t OPTION_OUTPUT_ATTRIBUTE;
 	static const string_t OPTION_BEFORE_RECORDS;
 	static const string_t OPTION_AFTER_RECORDS;
 	static const string_t OPTION_FOR_EACH;
@@ -78,6 +87,11 @@
 				else if (option == OPTION_RELATION) {
 					addRelation(c, currentRelation); // previous relation
 					currentRelation.relation = readNext(arguments, i);
+				} else if (option == OPTION_OUTPUT_ATTRIBUTE) {
+					relpipe::writer::AttributeMetadata attribute;
+					attribute.attributeName = readNext(arguments, i);
+					attribute.typeId = parseTypeId(readNext(arguments, i));
+					currentRelation.writerMetadata.push_back(attribute);
 				} else if (option == OPTION_DEFINE) {
 					DefinitionRecipe definition;
 					definition.name = readNext(arguments, i);
@@ -99,6 +113,7 @@
 };
 
 const string_t CLIParser::OPTION_RELATION = L"--relation";
+const string_t CLIParser::OPTION_OUTPUT_ATTRIBUTE = L"--output-attribute";
 const string_t CLIParser::OPTION_BEFORE_RECORDS = L"--before-records";
 const string_t CLIParser::OPTION_AFTER_RECORDS = L"--after-records";
 const string_t CLIParser::OPTION_FOR_EACH = L"--for-each";