author | František Kučera <franta-hg@frantovo.cz> |
Sat, 23 Jul 2022 21:36:01 +0200 | |
branch | v_0 |
changeset 3 | 3891db9e45b7 |
parent 1 | 27c11cea34de |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* Relational pipes |
|
3 |
* Copyright © 2022 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation, version 3 of the License. |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
*/ |
|
17 |
#pragma once |
|
18 |
||
19 |
#include <vector> |
|
20 |
#include <iostream> |
|
21 |
||
22 |
#include <relpipe/writer/typedefs.h> |
|
23 |
#include <relpipe/cli/CLI.h> |
|
24 |
#include <relpipe/cli/RelpipeCLIException.h> |
|
25 |
||
26 |
#include "Configuration.h" |
|
27 |
||
28 |
namespace relpipe { |
|
29 |
namespace in { |
|
30 |
namespace zeromq { |
|
31 |
||
32 |
class CLIParser { |
|
33 |
private: |
|
34 |
||
35 |
relpipe::writer::string_t readNext(const std::vector<relpipe::writer::string_t>& arguments, int& 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); |
|
38 |
} |
|
39 |
||
40 |
public: |
|
41 |
||
42 |
static const relpipe::writer::string_t OPTION_RELATION; |
|
3
3891db9e45b7
rename --endpoint-url to --connection-string
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
43 |
static const relpipe::writer::string_t OPTION_CONNECTION_STRING; |
0 | 44 |
static const relpipe::writer::string_t OPTION_MESSAGE_COUNT; |
45 |
||
46 |
Configuration parse(const std::vector<relpipe::writer::string_t>& arguments) { |
|
47 |
Configuration c; |
|
48 |
||
49 |
for (int i = 0; i < arguments.size();) { |
|
50 |
relpipe::writer::string_t option = readNext(arguments, i); |
|
1 | 51 |
|
0 | 52 |
if (option == OPTION_RELATION) { |
53 |
c.relation = readNext(arguments, i); |
|
3
3891db9e45b7
rename --endpoint-url to --connection-string
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
54 |
} else if (option == OPTION_CONNECTION_STRING) { |
3891db9e45b7
rename --endpoint-url to --connection-string
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
55 |
c.connectionString = readNext(arguments, i); |
0 | 56 |
} else if (option == OPTION_MESSAGE_COUNT) { |
57 |
c.messageCount = std::stoull(readNext(arguments, i)); |
|
58 |
} else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
|
59 |
} |
|
60 |
||
61 |
return c; |
|
62 |
} |
|
63 |
||
64 |
virtual ~CLIParser() { |
|
65 |
} |
|
66 |
}; |
|
67 |
||
68 |
const relpipe::writer::string_t CLIParser::OPTION_RELATION = L"--relation"; |
|
3
3891db9e45b7
rename --endpoint-url to --connection-string
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
69 |
const relpipe::writer::string_t CLIParser::OPTION_CONNECTION_STRING = L"--connection-string"; |
0 | 70 |
const relpipe::writer::string_t CLIParser::OPTION_MESSAGE_COUNT = L"--message-count"; |
71 |
||
72 |
} |
|
73 |
} |
|
74 |
} |