Dispatch returns a function which iterates a series of commands
looking for one to return something other than undefined.

@param commands
@returns {Function}
198580
function dispatch() {
  var commands = [].slice.call(arguments);

  return function fn() {
    var args = [].slice.call(arguments);
    var result;

    for (var i = 0; i < commands.length; i++) {
      result = commands[i].apply(undefined, args);

      if (result !== undefined) {
        break;
      }
    }

    return result;
  };
}
780430
function commandFactory(combos, cmd)
{
  var command;

  // if no combos provided
  // consider it as a single command run
  if (!cmd)
  {
    cmd = combos;
    combos = [{}];
  }

  command = partial(iterate, combos, cmd);
  command.commandDescription = partial(commandDescription, cmd);
  return command;
}
348218
public void defer(ICommandData[] commands) {
        deferredCommands.addAll(Arrays.asList(commands));
        for (ICommandData command : commands) {
            deferInternal(command);
        }
    }
369618
function exec (cmd) {

        var deferred = Q.defer();

        faithfulExec(cmd)
            .then(function (result) {
                deferred.resolve(result);
            }, function (result) {
                deferred.reject(result);
            });

        return deferred.promise;

    }
1134873
function run(commands, done) {
  var children = [];
  var pending = commands.length || 1;
  var err;
  each(commands, function(command, next) {
    children.push(childProcess.spawn(shell[0], [shell[1], command], {
      stdio: ['pipe', process.stdout, process.stderr]
    }).on('exit', function(code) {
      if (!err && code > 0) {
        err = new Error('`' + command + '` failed with exit code ' + code);
        children.forEach(function(child) {
          if (child.connected) child.kill();
        });
      }
      pending -= 1;
      if (pending === 0) done(err);
    }));
    next();
  });
}
973840
function dispatchToProps(dispatch) {
    return {
        add: function add() {
            var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
            var name = arguments[1];

            return dispatch({
                type: generateType(types.add, name),
                payload: {
                    name: name,
                    state: state
                }
            });
        },
        delete: function _delete(name) {
            return dispatch({
                type: generateType(types.delete, name),
                payload: {
                    name: name
                }
            });
        },
        reset: function reset() {
            var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
            var name = arguments[1];

            return dispatch({
                type: generateType(types.reset, name),
                payload: {
                    name: name,
                    state: state
                }
            });
        },
        set: function set() {
            var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
            var name = arguments[1];

            return dispatch({
                type: generateType(types.set, name),
                payload: {
                    name: name,
                    state: state
                }
            });
        }
    };
}
1306117
def dispatch_command(self, command, params=None):
        """"""
        try:
            if command in self.handlers:
                self.handlers[command](**params)
            else:
                logging.warning('Unsupported command: %s: %s',
                                command, params)
        except Exception as e:
            logging.warning('Error during command execution',
                            exc_info=sys.exc_info())
            raise e
543958
function Command (name, cli, action) {
  if (!(this instanceof Command)) {
    return new Command(name, cli, action)
  }
  this.name = name
  this.cli = cli
  this.action = action
}
301061
function() {
      for (var name in this.commands)
        if (this.commands.hasOwnProperty(name))
          this.commands[name][1].length ?
            this.main[name] = this.commands[name][1] :
              this.main.__defineGetter__(name, this.commands[name][1])
    }
882217
function cmd(args) {
            var def = Q.defer();
            grunt.util.spawn({ cmd: 'git', args: args }, def.resolve);
            return def.promise;
        }
1084641
def dispatch(cls, arguments, **kwargs):
        
        # first match wins
        # spec: all '-' elements must match, all others are False;
        #       '<sth>' elements are converted to call args on order of
        #       appearance
        #
        # kwargs are provided to dispatch call and used in func call
        for spec, func in cls._specs:
            # if command and arguments.get(command) and match(args):
            args = []  # specified args in order of appearance
            options = list(filter(lambda k: k.startswith('-') and
                                       (arguments[k] or k in spec),
                             arguments.keys()))
            cmds = list(filter(lambda k: not (k.startswith('-') or
                                         k.startswith('<')) and arguments[k],
                          arguments.keys()))
            args_spec = list(filter(lambda k: k.startswith('<'), spec))
            cmd_spec = list(filter(lambda k: not (k.startswith('-') or
                                             k.startswith('<')), spec))
            for element in spec:
                if element.startswith('-'):
                    # element is an option
                    if element in options:
                        args.append(arguments.get(element, False))
                        options.remove(element)
                elif element.startswith('<') and \
                        not arguments.get(element) is False:
                    # element is an argument
                    args.append(arguments.get(element))
                    if element in args_spec:
                        args_spec.remove(element)
                else:
                    # element is a command
                    if element in cmds and element in cmd_spec:
                        cmds.remove(element)
                        cmd_spec.remove(element)

            if options:
                continue  # not all options have been matched
            if cmds:
                continue  # not all cmds from command line have been matched
            if args_spec:
                continue  # not all args from spec have been provided
            if cmd_spec:
                continue  # not all cmds from spec have been provided
            # all options and cmds matched : call the cmd
            # TODO leave out all args to deal with "empty" signature
            exit_code = func(*args, **kwargs)
            return exit_code
        # no matching spec found
        raise Exception('No implementation for spec: %s' % arguments)
564486
def dispatch_subcommand(self, parser):
        '''
        
        '''
        # read in the subcommand
        args = parser.parse_args(sys.argv[1:2])

        # check that the subcommand is good
        if not hasattr(self, args.subcommand):
            print('Unrecognized command.')
            parser.print_help()
            exit(1)

        self.configs = ConfigurationLoader(DEFAULT_USER_CONFIG_PATH).load()

        # use dispatch pattern to invoke method with same name
        getattr(self, args.subcommand)()
188889
function getMatchingCommands(context, prefix) {
  var commands = cli.getMapping(context).requisition.system.commands;
  var reply = commands.getAll().filter(function(command) {
    if (command.hidden) {
      return false;
    }

    if (prefix && command.name.indexOf(prefix) !== 0) {
      // Filtered out because they don't match the search
      return false;
    }
    if (!prefix && command.name.indexOf(' ') != -1) {
      // We don't show sub commands with plain 'help'
      return false;
    }
    return true;
  });

  reply.sort(function(c1, c2) {
    return c1.name.localeCompare(c2.name);
  });

  reply = reply.map(function(command) {
    return command.toJson();
  });

  return reply;
}
1149868
function cmd(handlers)
{
  this.fieldindex = 0;
  this.state = "start";
  this.stmt = ""
  this.params = []

  // mixin all handlers
  for (var h in handlers)
  {
    this[h] = handlers[h];
  }
  // save command name to display in debug output
  this.command_name = cmd.caller.command_name;
  this.args = Array.prototype.slice.call(cmd.caller.arguments);
}
1116
function commander (options) {
    const { cmds, version } = options
    const argvs = parseArgs()
    if (argvs._.length === 0) {
        if (argvs.v || argvs.version) {
            process.stdout.write(version + '\n' || 'unknow\n')
            process.exit()
        } else {
            help(options)
        }
    } else {
        const cmd = cmds.filter(function (v) {
            return v.command === argvs._[0] || v.aliases === argvs._[0]
        })[0]
        
        if (!cmd) {
            help(options)
        }
        cmd.module.handler(argvs)
    }
}
1360728
def enqueue_command(self, command_name, args, options):
        """"""
        assert_open(self)
        promise = Promise()
        self.commands.append((command_name, args, options, promise))
        return promise
523010
function getCommand(commandName) {
    return _.find(commands, function (command) {
      return _.includes(command.aliases, commandName);
    });
  }