Skip to content
Myr

Prefix events to prevent conflicts between commands and options (#494)

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

authored by Augusto Franzoia · committed by Tomoaki Abe · parent 85450a0 · Browse files · 2 files+35 added−10 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+35 added−10 removed

  • tests:+25 added−0 removed
  • other:+10 added−10 removed

2 files+35 added−10 removed

added:test/test.command.noConflict.js+25 added
modified:index.js+10 added-10 removed
299 unmodified lines
300 fn.apply(self, args);301 };302 var parent = this.parent || this;303 var name = parent === this ? '*' : this._name;304 parent.on(name, listener);305 if (this._alias) parent.on(this._alias, listener);304 parent.on('command:' + name, listener);305 if (this._alias) parent.on('command:' + this._alias, listener);306 return this;307};308309/**
78 unmodified lines
388 this.options.push(option);389390 // when it's passed assign the value391 // and conditionally invoke the callback392 this.on(oname, function(val) {392 this.on('option:' + oname, function(val) {393 // coercion394 if (null !== val && fn) val = fn(val, undefined === self[name]395 ? defaultValue396 : self[name]);
225 unmodified lines
622 var name;623624 if (args.length) {625 name = args[0];626 if (this.listeners(name).length) {627 this.emit(args.shift(), args, unknown);626 if (this.listeners('command:' + name).length) {627 this.emit('command:' + args.shift(), args, unknown);628 } else {629 this.emit('*', args);629 this.emit('command:*', args);630 }631 } else {632 outputHelpIfNecessary(this, unknown);633
64 unmodified lines
698 // requires arg699 if (option.required) {700 arg = argv[++i];701 if (null == arg) return this.optionMissingArgument(option);702 this.emit(option.name(), arg);702 this.emit('option:' + option.name(), arg);703 // optional arg704 } else if (option.optional) {705 arg = argv[i+1];706 if (null == arg || ('-' == arg[0] && '-' != arg)) {707 arg = null;708 } else {709 ++i;710 }711 this.emit(option.name(), arg);711 this.emit('option:' + option.name(), arg);712 // bool713 } else {714 this.emit(option.name());714 this.emit('option:' + option.name());715 }716 continue;717 }718
112 unmodified lines
831 if (0 == arguments.length) return this._version;832 this._version = str;833 flags = flags || '-V, --version';834 this.option(flags, 'output the version number');835 this.on('version', function() {835 this.on('option:version', function() {836 process.stdout.write(str + '\n');837 process.exit(0);838 });839 return this;
291 unmodified lines