src/CLIParser.h
branchv_0
changeset 59 a1775ba6d056
parent 54 bc6e11cccdf4
--- a/src/CLIParser.h	Sat Apr 23 18:49:25 2022 +0200
+++ b/src/CLIParser.h	Sun Aug 28 18:03:13 2022 +0200
@@ -46,6 +46,12 @@
 		else if (value == L"false") return false;
 		else throw relpipe::cli::RelpipeCLIException(L"Unable to parse boolean value: " + value + L" (expecting true or false)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
 	}
+	
+	OnDuplicateRelation parseOnDuplicateRelation(const string_t& value) {
+		if (value == L"insert") return OnDuplicateRelation::Insert;
+		else if (value == L"fail") return OnDuplicateRelation::Fail;
+		else throw relpipe::cli::RelpipeCLIException(L"Unable to parse OnDuplicateRelation value: " + value + L" (expecting fail or insert)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
+	}
 
 	void addQuery(Configuration& c, Statement& currentQuery) {
 		if (currentQuery.sql.size()) {
@@ -59,6 +65,7 @@
 	static const string_t OPTION_RELATION;
 	static const string_t OPTION_TYPE_CAST;
 	static const string_t OPTION_PARAMETER;
+	static const string_t OPTION_ON_DUPLICATE_RELATION;
 	static const string_t OPTION_COPY;
 	static const string_t OPTION_COPY_RENAMED;
 	static const string_t OPTION_DATA_SOURCE_NAME;
@@ -85,6 +92,8 @@
 				Parameter parameter;
 				parameter.value = readNext(arguments, i);
 				currentQuery.parameters.push_back(parameter);
+			} else if (option == OPTION_ON_DUPLICATE_RELATION) {
+				c.onDuplicateRelation = parseOnDuplicateRelation(readNext(arguments, i));
 			} else if (option == OPTION_COPY) {
 				c.copyRelations.push_back({readNext(arguments, i), L"", false});
 			} else if (option == OPTION_COPY_RENAMED) {
@@ -115,6 +124,7 @@
 const string_t CLIParser::OPTION_RELATION = L"--relation";
 const string_t CLIParser::OPTION_TYPE_CAST = L"--type-cast";
 const string_t CLIParser::OPTION_PARAMETER = L"--parameter";
+const string_t CLIParser::OPTION_ON_DUPLICATE_RELATION = L"--on-duplicate-relation";
 const string_t CLIParser::OPTION_COPY = L"--copy";
 const string_t CLIParser::OPTION_COPY_RENAMED = L"--copy-renamed";
 const string_t CLIParser::OPTION_LIST_DATA_SOURCES = L"--list-data-sources";