35 relpipe::writer::string_t readNext(const std::vector<relpipe::writer::string_t>& arguments, int& i) { |
35 relpipe::writer::string_t readNext(const std::vector<relpipe::writer::string_t>& arguments, int& i) { |
36 if (i < arguments.size()) return arguments[i++]; |
36 if (i < arguments.size()) return arguments[i++]; |
37 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); |
37 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); |
38 } |
38 } |
39 |
39 |
40 /** |
|
41 * TODO: use a common method |
|
42 */ |
|
43 bool parseBoolean(const relpipe::writer::string_t& value) { |
|
44 if (value == L"true") return true; |
|
45 else if (value == L"false") return false; |
|
46 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); |
|
47 } |
|
48 |
|
49 /** |
|
50 * TODO: use a common method |
|
51 */ |
|
52 relpipe::writer::TypeId parseTypeId(const relpipe::writer::string_t& value) { |
|
53 using t = relpipe::writer::TypeId; |
|
54 if (value == L"string") return t::STRING; |
|
55 else if (value == L"integer") return t::INTEGER; |
|
56 else if (value == L"boolean") return t::BOOLEAN; |
|
57 else throw relpipe::cli::RelpipeCLIException(L"Unable to parse TypeId: " + value, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
|
58 } |
|
59 |
|
60 Configuration::ReadTypes parseReadTypes(const relpipe::writer::string_t& value) { |
|
61 if (value == L"auto") return Configuration::ReadTypes::AUTO; |
|
62 else if (value == L"true") return Configuration::ReadTypes::TRUE; |
|
63 else if (value == L"false") return Configuration::ReadTypes::FALSE; |
|
64 else throw relpipe::cli::RelpipeCLIException(L"Unable to parse ReadTypes: " + value, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
|
65 } |
|
66 |
|
67 public: |
40 public: |
68 |
41 |
69 static const relpipe::writer::string_t OPTION_RELATION; |
42 static const relpipe::writer::string_t OPTION_RELATION; |
70 static const relpipe::writer::string_t OPTION_ATTRIBUTE; |
43 static const relpipe::writer::string_t OPTION_QUEUE; |
71 static const relpipe::writer::string_t OPTION_READ_TYPES; |
44 static const relpipe::writer::string_t OPTION_MESSAGE_COUNT; |
72 |
45 |
73 Configuration parse(const std::vector<relpipe::writer::string_t>& arguments) { |
46 Configuration parse(const std::vector<relpipe::writer::string_t>& arguments) { |
74 Configuration c; |
47 Configuration c; |
75 |
48 |
76 for (int i = 0; i < arguments.size();) { |
49 for (int i = 0; i < arguments.size();) { |
77 relpipe::writer::string_t option = readNext(arguments, i); |
50 relpipe::writer::string_t option = readNext(arguments, i); |
78 |
51 |
79 if (option == OPTION_RELATION) { |
52 if (option == OPTION_RELATION) { |
80 c.relation = readNext(arguments, i); |
53 c.relation = readNext(arguments, i); |
81 } else if (option == OPTION_ATTRIBUTE) { |
54 } else if (option == OPTION_QUEUE) { |
82 AttributeRecipe attribute; |
55 c.queue = readNext(arguments, i); |
83 attribute.name = readNext(arguments, i); |
56 } else if (option == OPTION_MESSAGE_COUNT) { |
84 attribute.type = parseTypeId(readNext(arguments, i)); |
57 c.messageCount = std::stoull(readNext(arguments, i)); |
85 c.attributes.push_back(attribute); |
|
86 } else if (option == OPTION_READ_TYPES) { |
|
87 c.readTypes = parseReadTypes(readNext(arguments, i)); |
|
88 } else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
58 } else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
89 } |
59 } |
90 |
60 |
91 return c; |
61 return c; |
92 } |
62 } |