--- a/src/CLIParser.h Sat Mar 20 19:18:10 2021 +0100
+++ b/src/CLIParser.h Fri Mar 26 22:29:46 2021 +0100
@@ -37,17 +37,6 @@
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);
}
- void readNextRecord(const std::vector<relpipe::common::type::StringX>& arguments, int& i, RelationConfiguration& currentRelation) {
- for (const auto& a : currentRelation.attributes) currentRelation.values.emplace_back(readNext(arguments, i));
- }
-
- void addRelation(Configuration& c, RelationConfiguration& currentRelation) {
- if (currentRelation.relation.size()) {
- c.relationConfigurations.push_back(currentRelation);
- currentRelation = RelationConfiguration();
- }
- }
-
/**
* TODO: use a common method
*/
@@ -57,58 +46,23 @@
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);
}
- /**
- * TODO: use a common method
- */
- relpipe::writer::TypeId parseTypeId(const relpipe::common::type::StringX& 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 relpipe::common::type::StringX OPTION_RELATION;
- static const relpipe::common::type::StringX OPTION_WRITE_HEADER;
- static const relpipe::common::type::StringX OPTION_ATTRIBUTE;
- static const relpipe::common::type::StringX OPTION_RECORD;
- static const relpipe::common::type::StringX OPTION_RECORDS;
- static const relpipe::common::type::StringX OPTION_RECORDS_STDIN;
+ static const relpipe::common::type::StringX OPTION_LIST_INPUT_DEVICES;
+ static const relpipe::common::type::StringX OPTION_LIST_INPUT_EVENTS;
Configuration parse(const std::vector<relpipe::common::type::StringX>& arguments) {
Configuration c;
- RelationConfiguration currentRelation;
for (int i = 0; i < arguments.size();) {
relpipe::common::type::StringX option = readNext(arguments, i);
- if (option == OPTION_RELATION) {
- addRelation(c, currentRelation); // previous relation
- currentRelation.relation = readNext(arguments, i);
- } else if (option == OPTION_WRITE_HEADER) {
- currentRelation.writeHeader = parseBoolean(readNext(arguments, i));
- } else if (option == OPTION_ATTRIBUTE) {
- AttributeRecipe attribute;
- attribute.name = readNext(arguments, i);
- attribute.type = parseTypeId(readNext(arguments, i));
- currentRelation.attributes.push_back(attribute);
- } else if (option == OPTION_RECORD) {
- readNextRecord(arguments, i, currentRelation);
- } else if (option == OPTION_RECORDS) {
- while (i < arguments.size()) readNextRecord(arguments, i, currentRelation);
- } else if (option == OPTION_RECORDS_STDIN) {
- if (parseBoolean(readNext(arguments, i))) {
- for (RelationConfiguration r : c.relationConfigurations) if (r.valueStream) throw relpipe::cli::RelpipeCLIException(L"Only one relation can read data from STDIN.", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
- currentRelation.valueStream = &std::cin;
- }
+ if (option == OPTION_LIST_INPUT_DEVICES) {
+ c.listInputDevices = parseBoolean(readNext(arguments, i));
+ } else if (option == OPTION_LIST_INPUT_EVENTS) {
+ c.listInputEvents = parseBoolean(readNext(arguments, i));
} else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
}
- addRelation(c, currentRelation); // last relation
-
- if (c.relationConfigurations.size() == 0) throw relpipe::cli::RelpipeCLIException(L"There must be at least one relation. Use the " + OPTION_RELATION + L" option.", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
- for (auto& rc : c.relationConfigurations) if (rc.attributes.size() == 0) throw relpipe::cli::RelpipeCLIException(L"There must be at least one attribute. Use the " + OPTION_ATTRIBUTE + L" option.", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
return c;
}
@@ -117,12 +71,8 @@
}
};
-const relpipe::common::type::StringX CLIParser::OPTION_RELATION = L"--relation";
-const relpipe::common::type::StringX CLIParser::OPTION_WRITE_HEADER = L"--write-header";
-const relpipe::common::type::StringX CLIParser::OPTION_ATTRIBUTE = L"--attribute";
-const relpipe::common::type::StringX CLIParser::OPTION_RECORD = L"--record";
-const relpipe::common::type::StringX CLIParser::OPTION_RECORDS = L"--records";
-const relpipe::common::type::StringX CLIParser::OPTION_RECORDS_STDIN = L"--records-on-stdin";
+const relpipe::common::type::StringX CLIParser::OPTION_LIST_INPUT_DEVICES = L"--list-input-devices";
+const relpipe::common::type::StringX CLIParser::OPTION_LIST_INPUT_EVENTS = L"--list-input-events";
}
}