Skip to content
Myr

Do not mutate program.args when calling action handler (#1048)

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

authored by John Gee · committed by GitHub · parent 5cac9d6 · Browse files · 2 files+44 added−8 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+44 added−8 removed

  • tests:+36 added−0 removed
  • other:+8 added−8 removed

2 files+44 added−8 removed

added:tests/command.action.test.js+36 added
modified:index.js+8 added-8 removed
344 unmodified lines
345 args[i] = args.splice(i);346 }347 });348349 // Always append ourselves to the end of the arguments,350 // to make sure we match the number of arguments the user351 // expects352 if (self._args.length) {353 args[self._args.length] = self;354 } else {355 args.push(self);349 // The .action callback takes an extra parameter which is the command itself.350 var expectedArgsCount = self._args.length;351 var actionArgs = args.slice(0, expectedArgsCount);352 actionArgs[expectedArgsCount] = self;353 // Add the extra arguments so available too.354 if (args.length > expectedArgsCount) {355 actionArgs.push(args.slice(expectedArgsCount));356 }357358 fn.apply(self, args);358 fn.apply(self, actionArgs);359 };360 var parent = this.parent || this;361 var name = parent === this ? '*' : this._name;362 parent.on('command:' + name, listener);
1062 unmodified lines