src/CLIParser.h
branchv_0
changeset 2 f031a4dc7c52
parent 0 16c7fa9b7c49
child 5 d70ea23682aa
--- a/src/CLIParser.h	Sat Nov 21 20:09:18 2020 +0100
+++ b/src/CLIParser.h	Sun Nov 22 00:44:00 2020 +0100
@@ -37,9 +37,23 @@
 		else throw relpipe::cli::RelpipeCLIException(L"Missing CLI argument" + (i > 0 ? (L" after " + arguments[i - 1]) : L""), relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
 	}
 
+	/**
+	 * TODO: use a common method
+	 */
+	bool parseBoolean(const relpipe::writer::string_t& value) {
+		if (value == L"true") return true;
+		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);
+	}
+
 public:
 
 	static const relpipe::writer::string_t OPTION_RELATION;
+	static const relpipe::writer::string_t OPTION_ENABLE_SECTIONS;
+	static const relpipe::writer::string_t OPTION_ENABLE_SUBKEYS;
+	static const relpipe::writer::string_t OPTION_ENABLE_COMMENTS;
+	static const relpipe::writer::string_t OPTION_ENABLE_LINE_NUMBERS;
+	static const relpipe::writer::string_t OPTION_ENABLE_EVENT_NUMBERS;
 
 	Configuration parse(const std::vector<relpipe::writer::string_t>& arguments) {
 		Configuration c;
@@ -47,9 +61,13 @@
 		for (int i = 0; i < arguments.size();) {
 			relpipe::writer::string_t option = readNext(arguments, i);
 
-			if (option == OPTION_RELATION) {
-				c.relation = readNext(arguments, i);
-			} else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
+			if (option == OPTION_RELATION) c.relation = readNext(arguments, i);
+			else if (option == OPTION_ENABLE_SECTIONS) c.enableSections = parseBoolean(readNext(arguments, i));
+			else if (option == OPTION_ENABLE_SUBKEYS) c.enableSubkeys = parseBoolean(readNext(arguments, i));
+			else if (option == OPTION_ENABLE_COMMENTS) c.enableComments = parseBoolean(readNext(arguments, i));
+			else if (option == OPTION_ENABLE_LINE_NUMBERS) c.enableLineNumbers = parseBoolean(readNext(arguments, i));
+			else if (option == OPTION_ENABLE_EVENT_NUMBERS) c.enableEventNumbers = parseBoolean(readNext(arguments, i));
+			else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
 		}
 
 		return c;
@@ -60,6 +78,11 @@
 };
 
 const relpipe::writer::string_t CLIParser::OPTION_RELATION = L"--relation";
+const relpipe::writer::string_t CLIParser::OPTION_ENABLE_SECTIONS = L"--enable-sections";
+const relpipe::writer::string_t CLIParser::OPTION_ENABLE_SUBKEYS = L"--enable-subkeys";
+const relpipe::writer::string_t CLIParser::OPTION_ENABLE_COMMENTS = L"--enable-comments";
+const relpipe::writer::string_t CLIParser::OPTION_ENABLE_LINE_NUMBERS = L"--enable-line-numbers";
+const relpipe::writer::string_t CLIParser::OPTION_ENABLE_EVENT_NUMBERS = L"--enable-event-numbers";
 
 }
 }