Parses command arguments and processes @method parseArgs @param {Object} commandArgs @return {Object|null}
(commandArgs)
| 544 | @return {Object|null} |
| 545 | */ |
| 546 | parseArgs(commandArgs) { |
| 547 | let knownOpts = {}; // Parse options |
| 548 | let commandOptions = {}; |
| 549 | let parsedOptions; |
| 550 | |
| 551 | this.registerOptions(); |
| 552 | |
| 553 | let assembleAndValidateOption = function (option) { |
| 554 | return this.assignOption(option, parsedOptions, commandOptions); |
| 555 | }; |
| 556 | |
| 557 | let validateParsed = function (key) { |
| 558 | // ignore 'argv', 'h', and 'help' |
| 559 | if (!(key in commandOptions) && key !== 'argv' && key !== 'h' && key !== 'help') { |
| 560 | this.ui.writeLine( |
| 561 | chalk.yellow( |
| 562 | `The option '--${key}' is not registered with the '${this.name}' command. ` + |
| 563 | `Run \`ember ${this.name} --help\` for a list of supported options.` |
| 564 | ) |
| 565 | ); |
| 566 | } |
| 567 | if (typeof parsedOptions[key] !== 'object') { |
| 568 | commandOptions[camelize(key)] = parsedOptions[key]; |
| 569 | } |
| 570 | }; |
| 571 | |
| 572 | this.availableOptions.forEach((option) => { |
| 573 | if (typeof option.type !== 'string') { |
| 574 | knownOpts[option.name] = option.type; |
| 575 | } else if (option.type === 'Path') { |
| 576 | knownOpts[option.name] = path; |
| 577 | } else { |
| 578 | knownOpts[option.name] = String; |
| 579 | } |
| 580 | }); |
| 581 | |
| 582 | parsedOptions = nopt(knownOpts, this.optionsAliases, commandArgs, 0); |
| 583 | |
| 584 | if (!this.availableOptions.every(assembleAndValidateOption.bind(this))) { |
| 585 | return null; |
| 586 | } |
| 587 | |
| 588 | Object.keys(parsedOptions).map(validateParsed.bind(this)); |
| 589 | |
| 590 | return { |
| 591 | options: defaults(commandOptions, this.settings), |
| 592 | args: parsedOptions.argv.remain, |
| 593 | }; |
| 594 | }, |
| 595 | |
| 596 | /** |
| 597 | * @method run |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…