Skip to content
Myr

Merge pull request #310 from zhiyelee/uk

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

allow unknown function #138

authored by Zhiye Li · committed by Zhiye Li · parents 863e73a, bcda184 · Browse files · 2 files+52 added−1 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+52 added−1 removed

  • tests:+38 added−0 removed
  • other:+14 added−1 removed

2 files+52 added−1 removed

added:test/test.options.unknown.js+38 added
modified:index.js+14 added-1 removed
80 unmodified lines
81function Command(name) {82 this.commands = [];83 this.options = [];84 this._execs = [];85 this._allowUnknown = false;86 this._args = [];87 this._name = name;88}89
300 unmodified lines
390 return this;391};392393/**394 * Allow unknown options on the command line.395 *396 * @param {Boolean} arg if `true` or omitted, no error will be thrown397 * for unknown options.398 * @api public399 */400Command.prototype.allowUnknown = function(arg) {401 this._allowUnknown = arguments.length === 0 || arg;402 return this;403}404405/**406 * Parse `argv`, settings options and invoking commands when defined.407 *408 * @param {Array} argv409 * @return {Command} for chaining
136 unmodified lines
546 outputHelpIfNecessary(this, unknown);547548 // If there were no args and we have unknown options,549 // then they are extraneous and we need to error.537 if (unknown.length > 0) {550 if (!this._allowUnknown && unknown.length > 0) {551 this.unknownOption(unknown[0]);552 }553 }554
444 unmodified lines