| 571 | namespace tools { |
| 572 | |
| 573 | int CommandLineMain(std::vector<std::string> args) { |
| 574 | try { |
| 575 | const auto totalStart = std::chrono::steady_clock::now(); |
| 576 | TCLAP::CmdLine cmd("Open Chinese Convert (OpenCC) Command Line Tool", ' ', |
| 577 | OPENCC_VERSION); |
| 578 | OpenCCOutput cmdLineOutput; |
| 579 | cmd.setOutput(&cmdLineOutput); |
| 580 | |
| 581 | TCLAP::ValueArg<std::string> configArg( |
| 582 | "c", "config", "Configuration file", false /* required */, |
| 583 | "s2t.json" /* default */, "file" /* type */, cmd); |
| 584 | TCLAP::ValueArg<std::string> outputArg( |
| 585 | "o", "output", "Write converted text to <file>.", false /* required */, |
| 586 | "" /* default */, "file" /* type */, cmd); |
| 587 | TCLAP::ValueArg<std::string> inputArg( |
| 588 | "i", "input", "Read original text from <file>.", false /* required */, |
| 589 | "" /* default */, "file" /* type */, cmd); |
| 590 | TCLAP::ValueArg<bool> noFlushArg( |
| 591 | "", "noflush", "Disable flush for every line", false /* required */, |
| 592 | false /* default */, "bool" /* type */, cmd); |
| 593 | TCLAP::SwitchArg inPlaceArg( |
| 594 | "", "in-place", |
| 595 | "Allow overwriting the input file when input and output refer to the " |
| 596 | "same file.", |
| 597 | cmd, false); |
| 598 | TCLAP::MultiArg<std::string> pathArg( |
| 599 | "", "path", "Additional paths to locate config and dictionary files.", |
| 600 | false /* required */, "file" /* type */, cmd); |
| 601 | TCLAP::ValueArg<std::string> measuredResultArg( |
| 602 | "", "measured_result", |
| 603 | "Write measured timing results as JSON to <file>.", false /* required */, |
| 604 | "" /* default */, "file" /* type */, cmd); |
| 605 | TCLAP::SwitchArg segmentationArg( |
| 606 | "", "segmentation", |
| 607 | "Output segmentation result as JSON instead of converted text.", cmd, |
| 608 | false); |
| 609 | TCLAP::SwitchArg inspectArg( |
| 610 | "", "inspect", |
| 611 | "Output full inspection result (segmentation + per-stage conversion + " |
| 612 | "final output) as JSON.", |
| 613 | cmd, false); |
| 614 | TCLAP::SwitchArg includeTofuRiskDictionariesArg( |
| 615 | "", "include-tofu-risk-dictionaries", |
| 616 | "Include dictionaries marked as possibly outputting tofu, i.e. " |
| 617 | "Chinese characters that may render as missing-glyph boxes. By " |
| 618 | "default, the command line tool skips these dictionaries.", |
| 619 | cmd, false); |
| 620 | const std::string argv0String = args.empty() ? std::string() : args[0]; |
| 621 | Optional<std::string> resourceZipFileName = |
| 622 | Optional<std::string>::Null(); |
| 623 | std::vector<std::string> visibleArgs; |
| 624 | if (!args.empty()) { |
| 625 | visibleArgs.push_back(args[0]); |
| 626 | } |
| 627 | for (size_t i = 1; i < args.size(); i++) { |
| 628 | const std::string& arg = args[i]; |
| 629 | std::string value; |
| 630 | if (arg == "--resource-zip") { |
no test coverage detected