40 void addRelation(Configuration& c, RelationConfiguration& currentRelation) { |
40 void addRelation(Configuration& c, RelationConfiguration& currentRelation) { |
41 if (currentRelation.relation.size()) { |
41 if (currentRelation.relation.size()) { |
42 c.relationConfigurations.push_back(currentRelation); |
42 c.relationConfigurations.push_back(currentRelation); |
43 } else { |
43 } else { |
44 // no relation name given → global configuration |
44 // no relation name given → global configuration |
45 c.printTypes = currentRelation.printTypes; |
45 c.writeTypes = currentRelation.writeTypes; |
46 c.printRelationName = currentRelation.printRelationName; |
46 c.writeRelationName = currentRelation.writeRelationName; |
47 c.printRecordCount = currentRelation.printRecordCount; |
47 c.writeRecordCount = currentRelation.writeRecordCount; |
48 } |
48 } |
49 currentRelation = RelationConfiguration(); |
49 currentRelation = RelationConfiguration(); |
50 } |
50 } |
51 |
51 |
52 /** |
52 /** |
59 } |
59 } |
60 |
60 |
61 public: |
61 public: |
62 |
62 |
63 static const relpipe::reader::string_t OPTION_RELATION; |
63 static const relpipe::reader::string_t OPTION_RELATION; |
64 static const relpipe::reader::string_t OPTION_PRINT_TYPES; |
64 static const relpipe::reader::string_t OPTION_WRITE_TYPES; |
65 static const relpipe::reader::string_t OPTION_PRINT_RELATION_NAME; |
65 static const relpipe::reader::string_t OPTION_WRITE_RELATION_NAME; |
66 static const relpipe::reader::string_t OPTION_PRINT_RECORD_COUNT; |
66 static const relpipe::reader::string_t OPTION_WRITE_RECORD_COUNT; |
67 |
67 |
68 Configuration parse(const std::vector<relpipe::reader::string_t>& arguments) { |
68 Configuration parse(const std::vector<relpipe::reader::string_t>& arguments) { |
69 Configuration c; |
69 Configuration c; |
70 RelationConfiguration currentRelation; |
70 RelationConfiguration currentRelation; |
71 |
71 |
73 relpipe::reader::string_t option = readNext(arguments, i); |
73 relpipe::reader::string_t option = readNext(arguments, i); |
74 |
74 |
75 if (option == OPTION_RELATION) { |
75 if (option == OPTION_RELATION) { |
76 addRelation(c, currentRelation); // previous relation |
76 addRelation(c, currentRelation); // previous relation |
77 currentRelation.relation = readNext(arguments, i); |
77 currentRelation.relation = readNext(arguments, i); |
78 } else if (option == OPTION_PRINT_TYPES) { |
78 } else if (option == OPTION_WRITE_TYPES) { |
79 currentRelation.printTypes = parseBoolean(readNext(arguments, i)); |
79 currentRelation.writeTypes = parseBoolean(readNext(arguments, i)); |
80 } else if (option == OPTION_PRINT_RELATION_NAME) { |
80 } else if (option == OPTION_WRITE_RELATION_NAME) { |
81 currentRelation.printRelationName = parseBoolean(readNext(arguments, i)); |
81 currentRelation.writeRelationName = parseBoolean(readNext(arguments, i)); |
82 } else if (option == OPTION_PRINT_RECORD_COUNT) { |
82 } else if (option == OPTION_WRITE_RECORD_COUNT) { |
83 currentRelation.printRecordCount = parseBoolean(readNext(arguments, i)); |
83 currentRelation.writeRecordCount = parseBoolean(readNext(arguments, i)); |
84 } else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
84 } else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
85 } |
85 } |
86 |
86 |
87 addRelation(c, currentRelation); // last relation |
87 addRelation(c, currentRelation); // last relation |
88 |
88 |
92 virtual ~CLIParser() { |
92 virtual ~CLIParser() { |
93 } |
93 } |
94 }; |
94 }; |
95 |
95 |
96 const relpipe::reader::string_t CLIParser::OPTION_RELATION = L"--relation"; |
96 const relpipe::reader::string_t CLIParser::OPTION_RELATION = L"--relation"; |
97 const relpipe::reader::string_t CLIParser::OPTION_PRINT_TYPES = L"--print-types"; |
97 const relpipe::reader::string_t CLIParser::OPTION_WRITE_TYPES = L"--write-types"; |
98 const relpipe::reader::string_t CLIParser::OPTION_PRINT_RELATION_NAME = L"--print-relation-name"; |
98 const relpipe::reader::string_t CLIParser::OPTION_WRITE_RELATION_NAME = L"--write-relation-name"; |
99 const relpipe::reader::string_t CLIParser::OPTION_PRINT_RECORD_COUNT = L"--print-record-count"; |
99 const relpipe::reader::string_t CLIParser::OPTION_WRITE_RECORD_COUNT = L"--write-record-count"; |
100 |
100 |
101 } |
101 } |
102 } |
102 } |
103 } |
103 } |