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