author | František Kučera <franta-hg@frantovo.cz> |
Tue, 20 Oct 2020 23:48:51 +0200 | |
branch | v_0 |
changeset 15 | fb0099a20482 |
parent 14 | a7596589a5b0 |
child 18 | 4a0e3b828858 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* Relational pipes |
|
3 |
* Copyright © 2018 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 |
|
10
4bcf3fb7cc48
fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
0 | 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 |
||
14
a7596589a5b0
change CLI interface: options: --write-header
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
28 |
#include "Configuration.h" |
a7596589a5b0
change CLI interface: options: --write-header
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
29 |
#include "CLIParser.h" |
0 | 30 |
#include "CSVHandler.h" |
1
82f86dc48339
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
31 |
#include "RelpipeCSVWriterException.h" |
0 | 32 |
|
33 |
using namespace relpipe::cli; |
|
34 |
using namespace relpipe::reader; |
|
35 |
using namespace relpipe::out::csv; |
|
36 |
||
37 |
int main(int argc, char**argv) { |
|
38 |
CLI cli(argc, argv); |
|
2
75aeeb022302
untie STDIO → utilize buffering
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
39 |
CLI::untieStdIO(); |
0 | 40 |
|
41 |
int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
|
42 |
||
43 |
try { |
|
14
a7596589a5b0
change CLI interface: options: --write-header
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
44 |
CLIParser cliParser; |
a7596589a5b0
change CLI interface: options: --write-header
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
45 |
Configuration configuration = cliParser.parse(cli.arguments()); |
0 | 46 |
std::shared_ptr<RelationalReader> reader(Factory::create(std::cin)); |
14
a7596589a5b0
change CLI interface: options: --write-header
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
47 |
CSVHandler handler(std::cout, configuration); |
0 | 48 |
reader->addHandler(&handler); |
49 |
reader->process(); |
|
50 |
||
51 |
resultCode = CLI::EXIT_CODE_SUCCESS; |
|
52 |
||
53 |
} catch (RelpipeCLIException e) { |
|
54 |
fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str()); |
|
55 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
|
56 |
resultCode = e.getExitCode(); |
|
57 |
} catch (RelpipeReaderException e) { |
|
58 |
fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessge().c_str()); |
|
59 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
|
60 |
resultCode = CLI::EXIT_CODE_DATA_ERROR; |
|
1
82f86dc48339
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
61 |
} catch (RelpipeCSVWriterException e) { |
82f86dc48339
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
62 |
fwprintf(stderr, L"Error while generating CSV: %ls\n", e.getMessge().c_str()); |
82f86dc48339
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
63 |
resultCode = CLI::EXIT_CODE_DATA_ERROR; |
0 | 64 |
} |
65 |
||
66 |
return resultCode; |
|
67 |
} |