src/CLIParser.h
branchv_0
changeset 8 8730e2d0db0e
parent 7 ff69af3c67a3
child 15 917b8fbd29b9
equal deleted inserted replaced
7:ff69af3c67a3 8:8730e2d0db0e
    66 	static const string_t OPTION_RELATION;
    66 	static const string_t OPTION_RELATION;
    67 	static const string_t OPTION_NAME_IS_XPATH;
    67 	static const string_t OPTION_NAME_IS_XPATH;
    68 	static const string_t OPTION_RECORDS;
    68 	static const string_t OPTION_RECORDS;
    69 	static const string_t OPTION_ATTRIBUTE;
    69 	static const string_t OPTION_ATTRIBUTE;
    70 	static const string_t OPTION_XINCLUDE;
    70 	static const string_t OPTION_XINCLUDE;
       
    71 	static const string_t OPTION_MODE;
       
    72 	static const string_t OPTION_RAW_XML_NODELIST_WRAPPER;
       
    73 	static const string_t OPTION_RAW_XML_ATTRIBUTE_WRAPPER;
    71 
    74 
    72 	Configuration parse(const std::vector<string_t>& arguments) {
    75 	Configuration parse(const std::vector<string_t>& arguments) {
    73 		Configuration c;
    76 		Configuration c;
    74 		RelationConfiguration currentRelation;
    77 		RelationConfiguration currentRelation;
    75 
    78 
    88 				currentRelation.nameIsXPath = true;
    91 				currentRelation.nameIsXPath = true;
    89 			} else if (option == OPTION_RECORDS) {
    92 			} else if (option == OPTION_RECORDS) {
    90 				currentRelation.xpath = readNext(arguments, i);
    93 				currentRelation.xpath = readNext(arguments, i);
    91 			} else if (option == OPTION_ATTRIBUTE) {
    94 			} else if (option == OPTION_ATTRIBUTE) {
    92 				AttributeRecipe attribute;
    95 				AttributeRecipe attribute;
       
    96 				attribute.mode = currentRelation.mode;
       
    97 				attribute.rawXmlNodeListWrapper = currentRelation.rawXmlNodeListWrapper;
       
    98 				attribute.rawXmlAttributeWrapper = currentRelation.rawXmlAttributeWrapper;
    93 				attribute.name = readNext(arguments, i);
    99 				attribute.name = readNext(arguments, i);
    94 				attribute.type = parseTypeId(readNext(arguments, i));
   100 				attribute.type = parseTypeId(readNext(arguments, i));
    95 				attribute.xpath = readNext(arguments, i);
   101 				attribute.xpath = readNext(arguments, i);
    96 				currentRelation.attributes.push_back(attribute);
   102 				currentRelation.attributes.push_back(attribute);
       
   103 			} else if (option == OPTION_MODE) {
       
   104 				string_t modeName = readNext(arguments, i);
       
   105 				Mode mode;
       
   106 				if (modeName == L"string") mode = Mode::STRING;
       
   107 				else if (modeName == L"boolean") mode = Mode::BOOLEAN;
       
   108 				else if (modeName == L"raw-xml") mode = Mode::RAW_XML;
       
   109 				else if (modeName == L"line-number") mode = Mode::LINE_NUMBER;
       
   110 				else if (modeName == L"xpath") mode = Mode::XPATH;
       
   111 				else throw relpipe::cli::RelpipeCLIException(L"Unsupported mode: " + modeName, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
       
   112 				if (currentRelation.attributes.size()) currentRelation.attributes.back().mode = mode;
       
   113 				else currentRelation.mode = mode;
       
   114 			} else if (option == OPTION_RAW_XML_NODELIST_WRAPPER) {
       
   115 				XmlElementSkeleton w = {readNext(arguments, i), readNext(arguments, i), readNext(arguments, i)};
       
   116 				if (currentRelation.attributes.size()) currentRelation.attributes.back().rawXmlNodeListWrapper = w;
       
   117 				else currentRelation.rawXmlNodeListWrapper = w;
       
   118 			} else if (option == OPTION_RAW_XML_ATTRIBUTE_WRAPPER) {
       
   119 				XmlElementSkeleton w = {readNext(arguments, i), readNext(arguments, i), readNext(arguments, i)};
       
   120 				if (currentRelation.attributes.size()) currentRelation.attributes.back().rawXmlAttributeWrapper = w;
       
   121 				else currentRelation.rawXmlAttributeWrapper = w;
    97 			} else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
   122 			} else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
    98 		}
   123 		}
    99 		addRelation(c, currentRelation); // last relation
   124 		addRelation(c, currentRelation); // last relation
   100 
   125 
   101 		return c;
   126 		return c;
   109 const string_t CLIParser::OPTION_RELATION = L"--relation";
   134 const string_t CLIParser::OPTION_RELATION = L"--relation";
   110 const string_t CLIParser::OPTION_NAME_IS_XPATH = L"--name-is-xpath";
   135 const string_t CLIParser::OPTION_NAME_IS_XPATH = L"--name-is-xpath";
   111 const string_t CLIParser::OPTION_RECORDS = L"--records";
   136 const string_t CLIParser::OPTION_RECORDS = L"--records";
   112 const string_t CLIParser::OPTION_ATTRIBUTE = L"--attribute";
   137 const string_t CLIParser::OPTION_ATTRIBUTE = L"--attribute";
   113 const string_t CLIParser::OPTION_XINCLUDE = L"--xinclude";
   138 const string_t CLIParser::OPTION_XINCLUDE = L"--xinclude";
       
   139 const string_t CLIParser::OPTION_MODE = L"--mode";
       
   140 const string_t CLIParser::OPTION_RAW_XML_NODELIST_WRAPPER = L"--raw-xml-nodelist-wrapper";
       
   141 const string_t CLIParser::OPTION_RAW_XML_ATTRIBUTE_WRAPPER = L"--raw-xml-attribute-wrapper";
   114 
   142 
   115 }
   143 }
   116 }
   144 }
   117 }
   145 }