Skip to content
Myr

Use _getCommandAndAncestors() consistently

Before adoption: this commit came in with the history the project adopted, so no landing records it.

(cherry picked from commit 777a4528a6160171740fc795b517c7264d736d26)

authored by Wee Bit · committed by Abe Tomoaki · parent 1f90b11 · Browse files · 2 files+15 added−16 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+15 added−16 removed

  • other:+15 added−16 removed

2 files+15 added−16 removed

modified:lib/command.js+7 added-8 removed
1381 unmodified lines
1382 */13831384 _checkForMissingMandatoryOptions() {1385 // Walk up hierarchy so can call in subcommand after checking for displaying help.1386 for (let cmd = this; cmd; cmd = cmd.parent) {1386 this._getCommandAndAncestors().forEach((cmd) => {1387 cmd.options.forEach((anOption) => {1388 if (anOption.mandatory && (cmd.getOptionValue(anOption.attributeName()) === undefined)) {1389 cmd.missingMandatoryOptionValue(anOption);1390 }1391 });1392 }1392 });1393 }13941395 /**1396 * Display an error message if conflicting options are used together in this.
32 unmodified lines
1429 * @api private1430 */1431 _checkForConflictingOptions() {1432 // Walk up hierarchy so can call in subcommand after checking for displaying help.1433 for (let cmd = this; cmd; cmd = cmd.parent) {1433 this._getCommandAndAncestors().forEach((cmd) => {1434 cmd._checkForConflictingLocalOptions();1435 }1435 });1436 }14371438 /**1439 * Parse options from `argv` removing known options,
320 unmodified lines
17601761 if (flag.startsWith('--') && this._showSuggestionAfterError) {1762 // Looping to pick up the global options too1763 let candidateFlags = [];1764 let command = this;1765 do {1764 for (const command of this._getCommandAndAncestors()) {1765 const moreFlags = command.createHelp().visibleOptions(command)1766 .filter(option => option.long)1767 .map(option => option.long);1768 candidateFlags = candidateFlags.concat(moreFlags);1770 command = command.parent;1771 } while (command && !command._enablePositionalOptions);1769 if (command._enablePositionalOptions) break;1770 }1771 suggestion = suggestSimilar(flag, candidateFlags);1772 }17731774 const message = `error: unknown option '${flag}'${suggestion}`;
427 unmodified lines
modified:lib/help.js+8 added-8 removed
99 unmodified lines
100 visibleGlobalOptions(cmd) {101 if (!this.showGlobalOptions) return [];102103 const globalOptions = [];104 for (let parentCmd = cmd.parent; parentCmd; parentCmd = parentCmd.parent) {105 const visibleOptions = parentCmd.options.filter((option) => !option.hidden);104 cmd._getCommandAndAncestors().slice(1).forEach((ancestorCmd) => {105 const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);106 globalOptions.push(...visibleOptions);107 }107 });108 if (this.sortOptions) {109 globalOptions.sort(this.compareOptions);110 }111 return globalOptions;
127 unmodified lines
239 let cmdName = cmd._name;240 if (cmd._aliases[0]) {241 cmdName = cmdName + '|' + cmd._aliases[0];242 }243 let parentCmdNames = '';244 for (let parentCmd = cmd.parent; parentCmd; parentCmd = parentCmd.parent) {245 parentCmdNames = parentCmd.name() + ' ' + parentCmdNames;246 }247 return parentCmdNames + cmdName + ' ' + cmd.usage();243 let ancestorCmdNames = '';244 cmd._getCommandAndAncestors().slice(1).forEach((ancestorCmd) => {245 ancestorCmdNames = ancestorCmd.name() + ' ' + ancestorCmdNames;246 });247 return ancestorCmdNames + cmdName + ' ' + cmd.usage();248 }249250 /**251 * Get the description for the command.
213 unmodified lines