| 2544 | |
| 2545 | public: |
| 2546 | void init(int argc, char ** argv) |
| 2547 | { |
| 2548 | /// Don't parse options with Poco library. We need more sophisticated processing. |
| 2549 | stopOptionsProcessing(); |
| 2550 | |
| 2551 | /** We allow different groups of arguments: |
| 2552 | * - common arguments; |
| 2553 | * - arguments for any number of external tables each in form "--external args...", |
| 2554 | * where possible args are file, name, format, structure, types; |
| 2555 | * - param arguments for prepared statements. |
| 2556 | * Split these groups before processing. |
| 2557 | */ |
| 2558 | using Arguments = std::vector<std::string>; |
| 2559 | |
| 2560 | Arguments common_arguments{""}; /// 0th argument is ignored. |
| 2561 | std::vector<Arguments> external_tables_arguments; |
| 2562 | |
| 2563 | bool in_external_group = false; |
| 2564 | for (int arg_num = 1; arg_num < argc; ++arg_num) |
| 2565 | { |
| 2566 | const char * arg = argv[arg_num]; |
| 2567 | |
| 2568 | if (0 == strcmp(arg, "--external")) |
| 2569 | { |
| 2570 | in_external_group = true; |
| 2571 | external_tables_arguments.emplace_back(Arguments{""}); |
| 2572 | } |
| 2573 | /// Options with value after equal sign. |
| 2574 | else if ( |
| 2575 | in_external_group |
| 2576 | && (0 == strncmp(arg, "--file=", strlen("--file=")) || 0 == strncmp(arg, "--name=", strlen("--name=")) |
| 2577 | || 0 == strncmp(arg, "--format=", strlen("--format=")) || 0 == strncmp(arg, "--structure=", strlen("--structure=")) |
| 2578 | || 0 == strncmp(arg, "--types=", strlen("--types=")))) |
| 2579 | { |
| 2580 | external_tables_arguments.back().emplace_back(arg); |
| 2581 | } |
| 2582 | /// Options with value after whitespace. |
| 2583 | else if ( |
| 2584 | in_external_group |
| 2585 | && (0 == strcmp(arg, "--file") || 0 == strcmp(arg, "--name") || 0 == strcmp(arg, "--format") |
| 2586 | || 0 == strcmp(arg, "--structure") || 0 == strcmp(arg, "--types"))) |
| 2587 | { |
| 2588 | if (arg_num + 1 < argc) |
| 2589 | { |
| 2590 | external_tables_arguments.back().emplace_back(arg); |
| 2591 | ++arg_num; |
| 2592 | arg = argv[arg_num]; |
| 2593 | external_tables_arguments.back().emplace_back(arg); |
| 2594 | } |
| 2595 | else |
| 2596 | break; |
| 2597 | } |
| 2598 | else |
| 2599 | { |
| 2600 | in_external_group = false; |
| 2601 | |
| 2602 | /// Parameter arg after underline. |
| 2603 | if (startsWith(arg, "--param_")) |
no test coverage detected