MCPcopy
hub / github.com/tj/commander.js / action

Method action

lib/command.js:557–573  ·  view source on GitHub ↗

* Register callback `fn` for the command. * * @example * program * .command('serve') * .description('start service') * .action(function() { * // do work here * }); * * @param {Function} fn * @return {Command} `this` command for chaining

(fn)

Source from the content-addressed store, hash-verified

555 */
556
557 action(fn) {
558 const listener = (args) => {
559 // The .action callback takes an extra parameter which is the command or options.
560 const expectedArgsCount = this.registeredArguments.length;
561 const actionArgs = args.slice(0, expectedArgsCount);
562 if (this._storeOptionsAsProperties) {
563 actionArgs[expectedArgsCount] = this; // backwards compatible "options"
564 } else {
565 actionArgs[expectedArgsCount] = this.opts();
566 }
567 actionArgs.push(this);
568
569 return fn.apply(this, actionArgs);
570 };
571 this._actionHandler = listener;
572 return this;
573 }
574
575 /**
576 * Factory routine to create a new unattached option.

Calls

no outgoing calls

Tested by 6

createProgramFunction · 0.76
makeProgramFunction · 0.64
configureCommandFunction · 0.64
makeProgramFunction · 0.64
makeProgramFunction · 0.64
createProgram1032Function · 0.64