(
argv: Arguments,
positionalMap: Dictionary<string[]>,
parseOptions: Positionals,
yargs: YargsInstance
)
| 625 | // we run yargs-parser against the positional arguments |
| 626 | // applying the same parsing logic used for flags. |
| 627 | private postProcessPositionals( |
| 628 | argv: Arguments, |
| 629 | positionalMap: Dictionary<string[]>, |
| 630 | parseOptions: Positionals, |
| 631 | yargs: YargsInstance |
| 632 | ) { |
| 633 | // combine the parsing hints we've inferred from the command |
| 634 | // string with explicitly configured parsing hints. |
| 635 | const options = Object.assign({}, yargs.getOptions()); |
| 636 | options.default = Object.assign(parseOptions.default, options.default); |
| 637 | for (const key of Object.keys(parseOptions.alias)) { |
| 638 | options.alias[key] = (options.alias[key] || []).concat( |
| 639 | parseOptions.alias[key] |
| 640 | ); |
| 641 | } |
| 642 | options.array = options.array.concat(parseOptions.array); |
| 643 | options.config = {}; // don't load config when processing positionals. |
| 644 | |
| 645 | const unparsed: string[] = []; |
| 646 | Object.keys(positionalMap).forEach(key => { |
| 647 | positionalMap[key].map(value => { |
| 648 | if (options.configuration['unknown-options-as-args']) |
| 649 | options.key[key] = true; |
| 650 | unparsed.push(`--${key}`); |
| 651 | unparsed.push(value); |
| 652 | }); |
| 653 | }); |
| 654 | |
| 655 | // short-circuit parse. |
| 656 | if (!unparsed.length) return; |
| 657 | |
| 658 | const config: Configuration = Object.assign({}, options.configuration, { |
| 659 | 'populate--': false, |
| 660 | }); |
| 661 | |
| 662 | const parsed = this.shim.Parser.detailed( |
| 663 | unparsed, |
| 664 | Object.assign({}, options, { |
| 665 | configuration: config, |
| 666 | }) |
| 667 | ); |
| 668 | |
| 669 | if (parsed.error) { |
| 670 | yargs |
| 671 | .getInternalMethods() |
| 672 | .getUsageInstance() |
| 673 | .fail(parsed.error.message, parsed.error); |
| 674 | } else { |
| 675 | // only copy over positional keys (don't overwrite |
| 676 | // flag arguments that were already parsed). |
| 677 | const positionalKeys = Object.keys(positionalMap); |
| 678 | Object.keys(positionalMap).forEach(key => { |
| 679 | positionalKeys.push(...parsed.aliases[key]); |
| 680 | }); |
| 681 | |
| 682 | Object.keys(parsed.argv).forEach(key => { |
| 683 | if (positionalKeys.includes(key)) { |
| 684 | // any new aliases need to be placed in positionalMap, which |
no test coverage detected