src/CLIParser.h
author František Kučera <franta-hg@frantovo.cz>
Thu, 24 Sep 2020 20:42:34 +0200
branchv_0
changeset 47 329757999664
parent 46 ab27422a34b0
permissions -rw-r--r--
fail-fast: report missing --relation and --attribute early and avoid crashing without any useful error message
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
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
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#pragma once
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <vector>
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <iostream>
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <relpipe/writer/typedefs.h>
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <relpipe/cli/CLI.h>
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <relpipe/cli/RelpipeCLIException.h>
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
#include "Configuration.h"
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
namespace relpipe {
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
namespace in {
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
namespace cli {
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
class CLIParser {
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
private:
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
	relpipe::writer::string_t readNext(const std::vector<relpipe::writer::string_t>& arguments, int& i) {
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
		if (i < arguments.size()) return arguments[i++];
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    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);
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
	}
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
	void readNextRecord(const std::vector<relpipe::writer::string_t>& arguments, int& i, RelationConfiguration& currentRelation) {
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
		for (const auto& a : currentRelation.attributes) currentRelation.values.emplace_back(readNext(arguments, i));
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
	}
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
	void addRelation(Configuration& c, RelationConfiguration& currentRelation) {
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		if (currentRelation.relation.size()) {
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
			c.relationConfigurations.push_back(currentRelation);
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
			currentRelation = RelationConfiguration();
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
		}
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
	}
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
	/**
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
	 * TODO: use a common method
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
	 */
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
	bool parseBoolean(const relpipe::writer::string_t& value) {
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
		if (value == L"true") return true;
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
		else if (value == L"false") return false;
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
		else throw relpipe::cli::RelpipeCLIException(L"Unable to parse boolean value: " + value + L" (expecting true or false)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
	}
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
	/**
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
	 * TODO: use a common method
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
	 */
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
	relpipe::writer::TypeId parseTypeId(const relpipe::writer::string_t& value) {
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
		using t = relpipe::writer::TypeId;
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
		if (value == L"string") return t::STRING;
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
		else if (value == L"integer") return t::INTEGER;
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
		else if (value == L"boolean") return t::BOOLEAN;
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
		else throw relpipe::cli::RelpipeCLIException(L"Unable to parse TypeId: " + value, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
	}
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
public:
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
	static const relpipe::writer::string_t OPTION_RELATION;
44
dd7094457e44 add option: --write-header
František Kučera <franta-hg@frantovo.cz>
parents: 43
diff changeset
    74
	static const relpipe::writer::string_t OPTION_WRITE_HEADER;
43
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
	static const relpipe::writer::string_t OPTION_ATTRIBUTE;
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
	static const relpipe::writer::string_t OPTION_RECORD;
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    77
	static const relpipe::writer::string_t OPTION_RECORDS;
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    78
	static const relpipe::writer::string_t OPTION_RECORDS_STDIN;
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    79
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    80
	Configuration parse(const std::vector<relpipe::writer::string_t>& arguments) {
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    81
		Configuration c;
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    82
		RelationConfiguration currentRelation;
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    83
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    84
		for (int i = 0; i < arguments.size();) {
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
			relpipe::writer::string_t option = readNext(arguments, i);
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    86
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    87
			if (option == OPTION_RELATION) {
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    88
				addRelation(c, currentRelation); // previous relation
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    89
				currentRelation.relation = readNext(arguments, i);
44
dd7094457e44 add option: --write-header
František Kučera <franta-hg@frantovo.cz>
parents: 43
diff changeset
    90
			} else if (option == OPTION_WRITE_HEADER) {
dd7094457e44 add option: --write-header
František Kučera <franta-hg@frantovo.cz>
parents: 43
diff changeset
    91
				currentRelation.writeHeader = parseBoolean(readNext(arguments, i));
43
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    92
			} else if (option == OPTION_ATTRIBUTE) {
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    93
				AttributeRecipe attribute;
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    94
				attribute.name = readNext(arguments, i);
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    95
				attribute.type = parseTypeId(readNext(arguments, i));
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    96
				currentRelation.attributes.push_back(attribute);
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    97
			} else if (option == OPTION_RECORD) {
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    98
				readNextRecord(arguments, i, currentRelation);
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    99
			} else if (option == OPTION_RECORDS) {
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   100
				while (i < arguments.size()) readNextRecord(arguments, i, currentRelation);
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   101
			} else if (option == OPTION_RECORDS_STDIN) {
46
ab27422a34b0 rename --records-from-stdin to --records-on-stdin and add boolean parameter
František Kučera <franta-hg@frantovo.cz>
parents: 44
diff changeset
   102
				if (parseBoolean(readNext(arguments, i))) {
ab27422a34b0 rename --records-from-stdin to --records-on-stdin and add boolean parameter
František Kučera <franta-hg@frantovo.cz>
parents: 44
diff changeset
   103
					for (RelationConfiguration r : c.relationConfigurations) if (r.valueStream) throw relpipe::cli::RelpipeCLIException(L"Only one relation can read data from STDIN.", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
ab27422a34b0 rename --records-from-stdin to --records-on-stdin and add boolean parameter
František Kučera <franta-hg@frantovo.cz>
parents: 44
diff changeset
   104
					currentRelation.valueStream = &std::cin;
ab27422a34b0 rename --records-from-stdin to --records-on-stdin and add boolean parameter
František Kučera <franta-hg@frantovo.cz>
parents: 44
diff changeset
   105
				}
43
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   106
			} else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   107
		}
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   108
		addRelation(c, currentRelation); // last relation
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   109
47
329757999664 fail-fast: report missing --relation and --attribute early and avoid crashing without any useful error message
František Kučera <franta-hg@frantovo.cz>
parents: 46
diff changeset
   110
		if (c.relationConfigurations.size() == 0) throw relpipe::cli::RelpipeCLIException(L"There must be at least one relation. Use the " + OPTION_RELATION + L" option.", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
329757999664 fail-fast: report missing --relation and --attribute early and avoid crashing without any useful error message
František Kučera <franta-hg@frantovo.cz>
parents: 46
diff changeset
   111
		for (auto& rc : c.relationConfigurations) if (rc.attributes.size() == 0) throw relpipe::cli::RelpipeCLIException(L"There must be at least one attribute. Use the " + OPTION_ATTRIBUTE + L" option.", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
329757999664 fail-fast: report missing --relation and --attribute early and avoid crashing without any useful error message
František Kučera <franta-hg@frantovo.cz>
parents: 46
diff changeset
   112
43
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   113
		return c;
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   114
	}
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   115
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   116
	virtual ~CLIParser() {
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   117
	}
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   118
};
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   119
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   120
const relpipe::writer::string_t CLIParser::OPTION_RELATION = L"--relation";
44
dd7094457e44 add option: --write-header
František Kučera <franta-hg@frantovo.cz>
parents: 43
diff changeset
   121
const relpipe::writer::string_t CLIParser::OPTION_WRITE_HEADER = L"--write-header";
43
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   122
const relpipe::writer::string_t CLIParser::OPTION_ATTRIBUTE = L"--attribute";
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   123
const relpipe::writer::string_t CLIParser::OPTION_RECORD = L"--record";
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   124
const relpipe::writer::string_t CLIParser::OPTION_RECORDS = L"--records";
46
ab27422a34b0 rename --records-from-stdin to --records-on-stdin and add boolean parameter
František Kučera <franta-hg@frantovo.cz>
parents: 44
diff changeset
   125
const relpipe::writer::string_t CLIParser::OPTION_RECORDS_STDIN = L"--records-on-stdin";
43
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   126
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   127
}
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   128
}
3c8ea5dcf793 change CLI interface: options: --relation --attribute --record --records --records-from-stdin
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   129
}