src/relpipe-out-yaml.cpp
author František Kučera <franta-hg@frantovo.cz>
Sat, 27 Nov 2021 23:15:17 +0100
branchv_0
changeset 3 1e9a07d8a406
parent 0 c52ca92aa593
permissions -rw-r--r--
exception: fix typo: getMessge() → getMessage()
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info)
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#include <cstdlib>
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <memory>
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <relpipe/cli/CLI.h>
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <relpipe/cli/RelpipeCLIException.h>
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <relpipe/reader/Factory.h>
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
#include <relpipe/reader/RelationalReader.h>
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
#include <relpipe/reader/RelpipeReaderException.h>
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
#include "YAMLHandler.h"
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
using namespace relpipe::cli;
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
using namespace relpipe::reader;
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
using namespace relpipe::out::yaml;
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
int main(int argc, char**argv) {
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
	CLI cli(argc, argv);
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	CLI::untieStdIO();
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
	
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
	try {
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
		std::shared_ptr<RelationalReader> reader(Factory::create(std::cin));
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
		YAMLHandler handler(std::cout);
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
		reader->addHandler(&handler);
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
		reader->process();
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
		resultCode = CLI::EXIT_CODE_SUCCESS;
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
	} catch (RelpipeCLIException e) {
3
1e9a07d8a406 exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    49
		fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str());
0
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
		resultCode = e.getExitCode();
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
	} catch (RelpipeReaderException e) {
3
1e9a07d8a406 exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    53
		fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessage().c_str());
0
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
		resultCode = CLI::EXIT_CODE_DATA_ERROR;
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
	}
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
	return resultCode;
c52ca92aa593 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
}