50 static const string_t OPTION_RELATION; |
50 static const string_t OPTION_RELATION; |
51 static const string_t OPTION_TYPE_CAST; |
51 static const string_t OPTION_TYPE_CAST; |
52 static const string_t OPTION_PARAMETER; |
52 static const string_t OPTION_PARAMETER; |
53 static const string_t OPTION_COPY; |
53 static const string_t OPTION_COPY; |
54 static const string_t OPTION_COPY_RENAMED; |
54 static const string_t OPTION_COPY_RENAMED; |
55 static const string_t OPTION_FILE; |
55 static const string_t OPTION_DATA_SOURCE_NAME; |
56 static const string_t OPTION_FILE_KEEP; |
56 static const string_t OPTION_DATA_SOURCE_URL; |
57 static const string_t OPTION_LIST_DATA_SOURCES; |
57 static const string_t OPTION_LIST_DATA_SOURCES; |
58 |
58 |
59 Configuration parse(const std::vector<string_t>& arguments) { |
59 Configuration parse(const std::vector<string_t>& arguments) { |
60 Configuration c; |
60 Configuration c; |
61 Statement currentQuery; |
61 Statement currentQuery; |
78 currentQuery.parameters.push_back(parameter); |
78 currentQuery.parameters.push_back(parameter); |
79 } else if (option == OPTION_COPY) { |
79 } else if (option == OPTION_COPY) { |
80 c.copyRelations.push_back({readNext(arguments, i), L"", false}); |
80 c.copyRelations.push_back({readNext(arguments, i), L"", false}); |
81 } else if (option == OPTION_COPY_RENAMED) { |
81 } else if (option == OPTION_COPY_RENAMED) { |
82 c.copyRelations.push_back({readNext(arguments, i), readNext(arguments, i), true}); |
82 c.copyRelations.push_back({readNext(arguments, i), readNext(arguments, i), true}); |
83 } else if (option == OPTION_FILE) { |
83 } else if (option == OPTION_DATA_SOURCE_NAME) { |
84 c.file = readNext(arguments, i); |
84 c.dataSourceName = readNext(arguments, i); |
85 } else if (option == OPTION_FILE_KEEP) { |
85 } else if (option == OPTION_DATA_SOURCE_URL) { |
86 string_t value = readNext(arguments, i); |
86 c.dataSourceURL = readNext(arguments, i); |
87 if (value == L"auto") c.keepFile = KeepFile::Automatic; |
|
88 else if (value == L"true") c.keepFile = KeepFile::Always; |
|
89 else if (value == L"false") c.keepFile = KeepFile::Never; |
|
90 else throw relpipe::cli::RelpipeCLIException(L"Unsupported keep-file value: " + value + L" Expecting: true, false, auto", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
|
91 } else if (option == OPTION_LIST_DATA_SOURCES) { |
87 } else if (option == OPTION_LIST_DATA_SOURCES) { |
92 c.listDataSources = true; |
88 c.listDataSources = true; |
93 } else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
89 } else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
94 } |
90 } |
95 addQuery(c, currentQuery); // last relation |
91 addQuery(c, currentQuery); // last relation |
|
92 |
|
93 if (c.dataSourceName.size() && c.dataSourceURL.size()) throw relpipe::cli::RelpipeCLIException(L"Specify data source name or data source URL, not both.", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
96 |
94 |
97 return c; |
95 return c; |
98 } |
96 } |
99 |
97 |
100 virtual ~CLIParser() { |
98 virtual ~CLIParser() { |
108 const string_t CLIParser::OPTION_RELATION = L"--relation"; |
106 const string_t CLIParser::OPTION_RELATION = L"--relation"; |
109 const string_t CLIParser::OPTION_TYPE_CAST = L"--type-cast"; |
107 const string_t CLIParser::OPTION_TYPE_CAST = L"--type-cast"; |
110 const string_t CLIParser::OPTION_PARAMETER = L"--parameter"; |
108 const string_t CLIParser::OPTION_PARAMETER = L"--parameter"; |
111 const string_t CLIParser::OPTION_COPY = L"--copy"; |
109 const string_t CLIParser::OPTION_COPY = L"--copy"; |
112 const string_t CLIParser::OPTION_COPY_RENAMED = L"--copy-renamed"; |
110 const string_t CLIParser::OPTION_COPY_RENAMED = L"--copy-renamed"; |
113 const string_t CLIParser::OPTION_FILE = L"--file"; |
|
114 const string_t CLIParser::OPTION_FILE_KEEP = L"--file-keep"; |
|
115 const string_t CLIParser::OPTION_LIST_DATA_SOURCES = L"--list-data-sources"; |
111 const string_t CLIParser::OPTION_LIST_DATA_SOURCES = L"--list-data-sources"; |
|
112 const string_t CLIParser::OPTION_DATA_SOURCE_NAME = L"--data-source-name"; |
|
113 const string_t CLIParser::OPTION_DATA_SOURCE_URL = L"--data-source-url"; |
116 |
114 |
117 } |
115 } |
118 } |
116 } |
119 } |
117 } |