author | František Kučera <franta-hg@frantovo.cz> |
Sat, 27 Nov 2021 23:15:17 +0100 | |
branch | v_0 |
changeset 9 | 42dbdee1d9f0 |
parent 0 | 1bb084f84eb9 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* Relational pipes |
|
3 |
* Copyright © 2020 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 "Configuration.h" |
|
29 |
#include "CLIParser.h" |
|
30 |
#include "INIDispatchHandler.h" |
|
31 |
||
32 |
using namespace relpipe::cli; |
|
33 |
using namespace relpipe::reader; |
|
34 |
using namespace relpipe::out::ini; |
|
35 |
||
36 |
int main(int argc, char**argv) { |
|
37 |
CLI cli(argc, argv); |
|
38 |
CLI::untieStdIO(); |
|
39 |
||
40 |
int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
|
41 |
||
42 |
try { |
|
43 |
CLIParser cliParser; |
|
44 |
Configuration configuration = cliParser.parse(cli.arguments()); |
|
45 |
std::shared_ptr<RelationalReader> reader(Factory::create(std::cin)); |
|
46 |
INIDispatchHandler handler(std::cout, configuration); |
|
47 |
reader->addHandler(&handler); |
|
48 |
reader->process(); |
|
49 |
||
50 |
resultCode = CLI::EXIT_CODE_SUCCESS; |
|
51 |
||
52 |
} catch (RelpipeCLIException e) { |
|
9
42dbdee1d9f0
exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
53 |
fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str()); |
0 | 54 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
55 |
resultCode = e.getExitCode(); |
|
56 |
} catch (RelpipeReaderException e) { |
|
9
42dbdee1d9f0
exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
57 |
fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessage().c_str()); |
0 | 58 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
59 |
resultCode = CLI::EXIT_CODE_DATA_ERROR; |
|
60 |
} |
|
61 |
||
62 |
return resultCode; |
|
63 |
} |