lib/server.js
function delegate(req, res) {
  var cmd = req.info.command
    , method;

  if(!cmd.sub) {
    throw new Error('attempt to delegate with no subcommand info');
  }

  method = req.exec[cmd.sub.cmd];

  // subcommand is declared but the command exec handler
  // has not declared the method and is attempting to delegate
  // we treat this as unknown subcommand which allows partial
  // subcommand exec handlers that may call delegate but only
  // implement a subset of the declared subcommands
  if(typeof method !== 'function') {
    return res.send(StoreError.UnknownSubcommand);
  }

  // rewrite the cmd/args
  req.cmd = cmd.sub.cmd;
  req.args = cmd.sub.args;
  method.call(this, req, res);
}
function delegate(req, res) {
  var cmd = req.info.command
    , method;

  if(!cmd.sub) {
    throw new Error('attempt to delegate with no subcommand info');
  }

  method = req.exec[cmd.sub.cmd];

  // subcommand is declared but the command exec handler
  // has not declared the method and is attempting to delegate
  // we treat this as unknown subcommand which allows partial
  // subcommand exec handlers that may call delegate but only
  // implement a subset of the declared subcommands
  if(typeof method !== 'function') {
    return res.send(StoreError.UnknownSubcommand);
  }

  // rewrite the cmd/args
  req.cmd = cmd.sub.cmd;
  req.args = cmd.sub.args;
  method.call(this, req, res);
}
function delegate ( req , res ) { var cmd = req . info . command , method ; if ( ! cmd . sub ) { throw new Error ( 'attempt to delegate with no subcommand info' ) ; } method = req . exec [ cmd . sub . cmd ] ; // subcommand is declared but the command exec handler // has not declared the method and is attempting to delegate // we treat this as unknown subcommand which allows partial // subcommand exec handlers that may call delegate but only // implement a subset of the declared subcommands if ( typeof method !== 'function' ) { return res . send ( StoreError . UnknownSubcommand ) ; } // rewrite the cmd/args req . cmd = cmd . sub . cmd ; req . args = cmd . sub . args ; method . call ( this , req , res ) ; }
Delegate a subcommand to a method declared on the exec instance.
Delegate a subcommand to a method declared on the exec instance .