Merge pull request #318 from zhiyelee/rename
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Rename allowunknown to allowUnknownOption
authored by Zhiye Li · committed by Zhiye Li · parents 79f04b3, a2afb83 · Browse files · 3 files·+62 added−62 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+62 added−62 removed
- tests:+57 added−57 removed
- other:+5 added−5 removed
Provenance
- Commit
4ccfe0e- Tree
a52266e- Author
Zhiye Li <zhiyelee@gmail.com>- Committer
Zhiye Li <zhiyelee@gmail.com>- Parent 1
79f04b3- Parent 2
a2afb83
3 files changed+62 added−62 removed
added:test/test.command.allowUnknownOption.js+57 added
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657/** * Module dependencies. */
var util = require('util');var program = require('../') , should = require('should');
var oldProcessExit = process.exit;var oldConsoleError = console.error;
program .version('0.0.1') .option('-p, --pepper', 'add pepper');
var consoleErrors = [];process.exit = function () {};console.error = function () { consoleErrors.push(util.format.apply(util, arguments));};
program.parse('node test -m'.split(' '));consoleErrors.length.should.equal(3);
// test subcommandvar consoleErrors = [];program .command('sub') .action(function () { });program.parse('node test sub -m'.split(' '));consoleErrors.length.should.equal(3);
consoleErrors = [];program .version('0.0.1') .option('-p, --pepper', 'add pepper');
program .allowUnknownOption() .parse('node test -m'.split(' '));consoleErrors.length.should.equal(0);
// test subcommandvar consoleErrors = [];program .command('sub') .allowUnknownOption() .action(function () { });program.parse('node test sub -m'.split(' '));consoleErrors.length.should.equal(3);
process.exit = oldProcessExit;console.error = oldConsoleError;
deleted:test/test.options.allowUnknown.js-57 removed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657/** * Module dependencies. */
var util = require('util');var program = require('../') , should = require('should');
var oldProcessExit = process.exit;var oldConsoleError = console.error;
program .version('0.0.1') .option('-p, --pepper', 'add pepper');
var consoleErrors = [];process.exit = function () {};console.error = function () { consoleErrors.push(util.format.apply(util, arguments));};
program.parse('node test -m'.split(' '));consoleErrors.length.should.equal(3);
// test subcommandvar consoleErrors = [];program .command('sub') .action(function () { });program.parse('node test sub -m'.split(' '));consoleErrors.length.should.equal(3);
consoleErrors = [];program .version('0.0.1') .option('-p, --pepper', 'add pepper');
program .allowUnknown() .parse('node test -m'.split(' '));consoleErrors.length.should.equal(0);
// test subcommandvar consoleErrors = [];program .command('sub') .allowUnknown() .action(function () { });program.parse('node test sub -m'.split(' '));consoleErrors.length.should.equal(3);
process.exit = oldProcessExit;console.error = oldConsoleError;
modified:index.js+5 added-5 removed
80 unmodified lines81 function Command(name) {82 this.commands = [];83 this.options = [];84 this._execs = [];85- this._allowUnknown = false;85+ this._allowUnknownOption = false;86 this._args = [];87 this._name = name;88 }89 306 unmodified lines396 * @param {Boolean} arg if `true` or omitted, no error will be thrown397 * for unknown options.398 * @api public399 */400-Command.prototype.allowUnknown = function(arg) {401- this._allowUnknown = arguments.length === 0 || arg;400+Command.prototype.allowUnknownOption = function(arg) {401+ this._allowUnknownOption = arguments.length === 0 || arg;402 return this;403-}403+};404 405 /**406 * Parse `argv`, settings options and invoking commands when defined.407 *299 unmodified lines707 * @api private708 */709 710 Command.prototype.unknownOption = function(flag) {711- if(this._allowUnknown) return;711+ if(this._allowUnknownOption) return;712 console.error();713 console.error(" error: unknown option `%s'", flag);714 console.error();715 process.exit(1);305 unmodified lines