Skip to content
Myr

Run default command if it's not just * (#1062)

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

* Run default command if it's not just * * Fix lint error * Add prgm action, only emit command:* when it's registered * Test asterisk handler not called without args * Restore check to not call program when signature wrong, and expand program tests * Document and rework and extend asterisk tests * Update * and program-action logic based on PR feedback * Rename program-action to program-command * Remove unnecessary command listener

authored by Justin Bennett · committed by John Gee · parent 9de0968 · Browse files · 3 files+133 added−36 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+133 added−36 removed

  • tests:+123 added−30 removed
  • other:+10 added−6 removed

3 files+133 added−36 removed

modified:tests/command.action.test.js+27 added-2 removed
modified:tests/command.asterisk.test.js+96 added-28 removed
modified:index.js+10 added-6 removed
367 unmodified lines
368369 fn.apply(self, actionArgs);370 };371 var parent = this.parent || this;372 var name = parent === this ? '*' : this._name;373 parent.on('command:' + name, listener);372 if (parent === this) {373 parent.on('program-command', listener);374 } else {375 parent.on('command:' + this._name, listener);376 }377378 if (this._alias) parent.on('command:' + this._alias, listener);379 return this;380};381
491 unmodified lines
873 name = args[0];874 if (this.listeners('command:' + name).length) {875 this.emit('command:' + args.shift(), args, unknown);876 } else {877 this.emit('program-command', args, unknown);878 this.emit('command:*', args, unknown);879 }880 } else {881 outputHelpIfNecessary(this, unknown);877882 // If there were no args and we have unknown options,883 // then they are extraneous and we need to error.884 if (unknown.length > 0 && !this.defaultExecutable) {885 this.unknownOption(unknown[0]);886 }883 if (this.commands.length === 0 &&884 this._args.filter(function(a) { return a.required; }).length === 0) {885 this.emit('command:*');887 // Call the program action handler, unless it has a (missing) required parameter and signature does not match.888 if (this._args.filter(function(a) { return a.required; }).length === 0) {889 this.emit('program-command');890 }891 }892893 return this;
739 unmodified lines