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::common::type::StringX& 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 public: |
40 public: |
50 |
41 |
51 static const relpipe::writer::string_t OPTION_RELATION; |
42 static const relpipe::writer::string_t OPTION_RELATION; |
52 static const relpipe::writer::string_t OPTION_UNLINK_ON_CLOSE; |
43 static const relpipe::writer::string_t OPTION_ENDPOINT_URL; |
53 static const relpipe::writer::string_t OPTION_QUEUE; |
|
54 static const relpipe::writer::string_t OPTION_MESSAGE_COUNT; |
44 static const relpipe::writer::string_t OPTION_MESSAGE_COUNT; |
55 |
45 |
56 Configuration parse(const std::vector<relpipe::writer::string_t>& arguments) { |
46 Configuration parse(const std::vector<relpipe::writer::string_t>& arguments) { |
57 Configuration c; |
47 Configuration c; |
58 |
48 |
59 for (int i = 0; i < arguments.size();) { |
49 for (int i = 0; i < arguments.size();) { |
60 relpipe::writer::string_t option = readNext(arguments, i); |
50 relpipe::writer::string_t option = readNext(arguments, i); |
61 |
51 |
62 if (option == OPTION_RELATION) { |
52 if (option == OPTION_RELATION) { |
63 c.relation = readNext(arguments, i); |
53 c.relation = readNext(arguments, i); |
64 } else if (option == OPTION_UNLINK_ON_CLOSE) { |
54 } else if (option == OPTION_ENDPOINT_URL) { |
65 c.unlinkOnClose = parseBoolean(readNext(arguments, i)); |
55 c.endpointUrl = readNext(arguments, i); |
66 } else if (option == OPTION_QUEUE) { |
|
67 c.queue = readNext(arguments, i); |
|
68 } else if (option == OPTION_MESSAGE_COUNT) { |
56 } else if (option == OPTION_MESSAGE_COUNT) { |
69 c.messageCount = std::stoull(readNext(arguments, i)); |
57 c.messageCount = std::stoull(readNext(arguments, i)); |
70 } 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); |
71 } |
59 } |
72 |
60 |