|
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 |
|
18 #include <cstdlib> |
|
19 #include <memory> |
|
20 |
|
21 #include <relpipe/cli/CLI.h> |
|
22 #include <relpipe/cli/RelpipeCLIException.h> |
|
23 |
|
24 #include <relpipe/reader/Factory.h> |
|
25 #include <relpipe/reader/RelationalReader.h> |
|
26 #include <relpipe/reader/RelpipeReaderException.h> |
|
27 |
|
28 #include "AMQPHandler.h" |
|
29 #include "CLIParser.h" |
|
30 #include "Configuration.h" |
|
31 |
|
32 using namespace relpipe::cli; |
|
33 using namespace relpipe::reader; |
|
34 using namespace relpipe::out::amqp; |
|
35 |
|
36 int main(int argc, char**argv) { |
|
37 setlocale(LC_ALL, ""); |
|
38 CLI::untieStdIO(); |
|
39 CLI cli(argc, argv); |
|
40 |
|
41 int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
|
42 |
|
43 try { |
|
44 CLIParser cliParser; |
|
45 Configuration configuration = cliParser.parse(cli.arguments()); |
|
46 std::shared_ptr<RelationalReader> reader(Factory::create(std::cin)); |
|
47 AMQPHandler handler(configuration); |
|
48 reader->addHandler(&handler); |
|
49 reader->process(); |
|
50 resultCode = CLI::EXIT_CODE_SUCCESS; |
|
51 } catch (RelpipeCLIException e) { |
|
52 fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str()); |
|
53 fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
|
54 resultCode = e.getExitCode(); |
|
55 } catch (RelpipeReaderException e) { |
|
56 fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessage().c_str()); |
|
57 fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
|
58 resultCode = CLI::EXIT_CODE_DATA_ERROR; |
|
59 } |
|
60 |
|
61 return resultCode; |
|
62 } |