70 |
70 |
71 Configuration parse(const std::vector<string_t>& arguments) { |
71 Configuration parse(const std::vector<string_t>& arguments) { |
72 Configuration c; |
72 Configuration c; |
73 RelationConfiguration currentRelation; |
73 RelationConfiguration currentRelation; |
74 |
74 |
75 { |
75 for (int i = 0; i < arguments.size();) { |
76 for (int i = 0; i < arguments.size();) { |
76 string_t option = readNext(arguments, i); |
77 string_t option = readNext(arguments, i); |
|
78 |
77 |
79 if (option == OPTION_BEFORE_RECORDS) currentRelation.guileBeforeRecords = readNext(arguments, i); |
78 if (option == OPTION_BEFORE_RECORDS) currentRelation.guileBeforeRecords = readNext(arguments, i); |
80 else if (option == OPTION_AFTER_RECORDS) currentRelation.guileAfterRecords = readNext(arguments, i); |
79 else if (option == OPTION_AFTER_RECORDS) currentRelation.guileAfterRecords = readNext(arguments, i); |
81 else if (option == OPTION_FOR_EACH) currentRelation.guileForEach = readNext(arguments, i); |
80 else if (option == OPTION_FOR_EACH) currentRelation.guileForEach = readNext(arguments, i); |
82 else if (option == OPTION_WHERE) currentRelation.guileWhere = readNext(arguments, i); |
81 else if (option == OPTION_WHERE) currentRelation.guileWhere = readNext(arguments, i); |
83 else if (option == OPTION_HAS_MORE_RECORDS) currentRelation.guileHasMoreRecords = readNext(arguments, i); |
82 else if (option == OPTION_HAS_MORE_RECORDS) currentRelation.guileHasMoreRecords = readNext(arguments, i); |
84 else if (option == OPTION_DROP) currentRelation.drop = true; |
83 else if (option == OPTION_DROP) currentRelation.drop = true; |
85 else if (option == OPTION_INPUT_ATTRIBUTES_APPEND) currentRelation.inputAttributesAppend = true; |
84 else if (option == OPTION_INPUT_ATTRIBUTES_APPEND) currentRelation.inputAttributesAppend = true; |
86 else if (option == OPTION_INPUT_ATTRIBUTES_PREPEND) currentRelation.inputAttributesPrepend = true; |
85 else if (option == OPTION_INPUT_ATTRIBUTES_PREPEND) currentRelation.inputAttributesPrepend = true; |
87 else if (option == OPTION_RELATION) { |
86 else if (option == OPTION_RELATION) { |
88 addRelation(c, currentRelation); // previous relation |
87 addRelation(c, currentRelation); // previous relation |
89 currentRelation.relation = readNext(arguments, i); |
88 currentRelation.relation = readNext(arguments, i); |
90 } else if (option == OPTION_OUTPUT_ATTRIBUTE) { |
89 } else if (option == OPTION_OUTPUT_ATTRIBUTE) { |
91 relpipe::writer::AttributeMetadata attribute; |
90 relpipe::writer::AttributeMetadata attribute; |
92 attribute.attributeName = readNext(arguments, i); |
91 attribute.attributeName = readNext(arguments, i); |
93 attribute.typeId = parseTypeId(readNext(arguments, i)); |
92 attribute.typeId = parseTypeId(readNext(arguments, i)); |
94 currentRelation.writerMetadata.push_back(attribute); |
93 currentRelation.writerMetadata.push_back(attribute); |
95 } else if (option == OPTION_DEFINE) { |
94 } else if (option == OPTION_DEFINE) { |
96 DefinitionRecipe definition; |
95 DefinitionRecipe definition; |
97 definition.name = readNext(arguments, i); |
96 definition.name = readNext(arguments, i); |
98 definition.type = readNext(arguments, i); |
97 definition.type = readNext(arguments, i); |
99 definition.value = readNext(arguments, i); |
98 definition.value = readNext(arguments, i); |
100 if (currentRelation.relation.size()) currentRelation.definitions.push_back(definition); |
99 if (currentRelation.relation.size()) currentRelation.definitions.push_back(definition); |
101 else c.definitions.push_back(definition); |
100 else c.definitions.push_back(definition); |
102 } else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
101 } else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
103 |
|
104 } |
|
105 |
102 |
106 addRelation(c, currentRelation); // last relation |
103 addRelation(c, currentRelation); // last relation |
107 } |
104 } |
108 |
105 |
109 return c; |
106 return c; |