When we know that we've
exceeded a known command, grab
on to that command and return it,
fixing the overall input context
at the same time.

@param {Object} input
@param {Array} commands
@return {Object}
@api private
764241
function getMatchObject(input, commands) {
  var len = input.context.length;
  var trimmed = String(input.context).replace(/^\s+/g, '');
  var prefix = new Array((len - trimmed.length) + 1).join(' ');
  var match;
  var suffix;
  commands.forEach(function (cmd) {
    var nextChar = trimmed.substr(cmd.length, 1);
    if (trimmed.substr(0, cmd.length) === cmd && String(cmd).trim() !== '' && nextChar === ' ') {
      match = cmd;
      suffix = trimmed.substr(cmd.length);
      prefix += trimmed.substr(0, cmd.length);
    }
  });

  var matchObject = (match) ?
    _.find(this.parent.commands, {_name: String(match).trim()}) :
    undefined;

  if (!matchObject) {
    this.parent.commands.forEach(function (cmd) {
      if ((cmd._aliases || []).indexOf(String(match).trim()) > -1) {
        matchObject = cmd;
      }
      return;
    });
  }

  if (!matchObject) {
    matchObject = _.find(this.parent.commands, {_catch: true});
    if (matchObject) {
      suffix = input.context;
    }
  }

  if (!matchObject) {
    prefix = input.context;
    suffix = '';
  }

  if (matchObject) {
    input.match = matchObject;
    input.prefix += prefix;
    input.context = suffix;
  }
  return input;
}
917975
function decoded(err, reply) {
  //console.error('got decoder err %s', err );
  //console.error('got decoder reply %j',reply );
  var res = new Response(this), req, cmd, args;
  if(err) {
    // return decoder errors to the client
    return res.send(err);
  }

  // we should only be handling array request types
  if(!Array.isArray(reply)) {
    return res.send(new Error('bad request, array expected'));
  }else if(!reply.length) {
    return res.send(new Error('bad request, empty array invalid'));
  }

  cmd = reply.shift();

  if(cmd instanceof Buffer) cmd = cmd.toString();

  if(typeof cmd !== 'string') {
    return res.send(new Error('bad request, string command expected'));
  }

  cmd = cmd.toLowerCase();

  // keep track of last command
  this._client.cmd = cmd;

  //console.error('got decoder cmd %s', cmd );
  //console.error('got decoder args %j', reply );

  req = new Request(this, cmd, reply);

  this.emit('command', req, res);
}
547742
function compile(context, commands) {
    let ii, cmd, limitOptions;

    // log.debug('limit: in-compile cmds:', commands);

    // look for the limit commands within the commands
    for (ii = commands.length - 1; ii >= 0; ii--) {
        cmd = commands[ii];
        if (cmd[0] === LIMIT) {
            // cmdLimit = cmd;
            limitOptions = {
                offset: context.valueOf(cmd[2]),
                limit: context.valueOf(cmd[1])
            };
            commands.splice(ii, 1);
        } else if (limitOptions && cmd[0] === ENTITY_FILTER) {
            // set the options object of the entityFilter command
            if (limitOptions) {
                cmd[3] = { ...cmd[3], ...limitOptions };
            }
            limitOptions = null;
        }
    }

    // if we still have an open limit and no entity filter was found, add one
    if (limitOptions) {
        commands.unshift([ENTITY_FILTER, null, null, limitOptions]);
    }

    return commands;
}
1191370
function ImportCommand(value, engine) {
        var match = value.match(/^\s*([a-z0-9\/\._-]+)\s*$/i);
        if (!match) {
            throw new Error('Invalid ' + this.type + ' syntax: ' + value);
        }

        this.name = match[1];
        Command.call(this, value, engine);
        this.cloneProps = ['name', 'state', 'blocks', 'target'];
        this.blocks = {};
    }
683746
def resolve command_string
      if detected_command = @commands.detect{|cmd| cmd.matches? command_string }
        detected_command
      elsif parent_context
        parent_context.resolve(command_string)
      else
        raise "Command #{command_string} could not be resolved from the current context."
      end
    end
545750
function fixInputChange(input) {
    let files;
    Object.defineProperty(input, 'files', {
        set(v) { files = v; dispatchEvent(input, 'change'); },
        get(v) { return files }
    });
}
511470
function onError(reason, commands) {
        if (typeof reason !== 'string' && typeof reason.message === 'string') {
            reason = reason.message;
        }
        return commands._replyFn(`An unexpected error \`${reason}\` occured and your commands could not be processed!`);
    }
321052
function getCommands( str ){
	var commands = str.split('|');

	commands.forEach(function( command, key ){
		var args = command.split(':');

		args.forEach(function( arg, k ){
			args[k] = trim( arg );
		});

		commands[key] = {
			command: command,
			method: args.shift(),
			args: args
		};
	});

	return commands;
}
1054759
function(eventType, commandClass)
	{
		if (!eventType) throw new Error('eventType cannot be undefined');
		if (!commandClass) throw new Error('commandClass for '+eventType+' cannot be undefined');
		
		if (this.__commands[eventType] && this.__commands[eventType].indexOf(commandClass) != -1)
		{
			return this;
		}
		
		this.__commands[eventType] = this.__commands[eventType] || [];
		this.__commands[eventType].push(commandClass);
		
		return this;
	}
355468
function encodeCommand(command) {
  const topInfo = Buffer.from(`*${command.length}\r\n`)
  const parts = command.map(adjustCommandArgument)
                  .map(x => Buffer.from(`\$${x.length}\r\n${x}\r\n`))

  parts.unshift(topInfo)
  return Buffer.concat(parts)
}
71824
function getSubCommands(context, command) {
  var commands = cli.getMapping(context).requisition.system.commands;
  var subcommands = commands.getAll().filter(function(subcommand) {
    return subcommand.name.indexOf(command.name) === 0 &&
           subcommand.name !== command.name &&
           !subcommand.hidden;
  });

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

  subcommands = subcommands.map(function(subcommand) {
    return subcommand.toJson();
  });

  return subcommands;
}
1318888
function mergeCommands(commands) {
  const cmds = filterCommands(commands);
  if (cmds.length === 0) {
    throw new Error('Expected at least one non-empty command');
  } else if (cmds.length === 1) {
    return cmds[0];
  } else {
    // Quote the arguments in each command and join them all using &&.
    const script = cmds.map(quote).join(' && ');
    return ['/bin/sh', '-c', script];
  }
}
1147465
function(input) {
		var needstesting = !this._matches.length;
		if (needstesting || this._matches.every(function(match) {
			return match.$instanceid !== input.$instanceid;
		})) {
			return this._maybeinput(input);
		}
		return false;
	}
233781
function parseInput(input) {
  var match = re.exec(input);

  if (match !== null) {
    var _match = _slicedToArray(match, 6),
        pre_keyword = _match[1],
        operator_keyword = _match[2],
        value = _match[3],
        unit = _match[4],
        post_keyword = _match[5];

    if (pre_keyword && post_keyword || pre_keyword && operator_keyword || post_keyword && operator_keyword) {
      return null;
    }

    return {
      value: sanitizeValue({
        value: value,
        operator_keyword: operator_keyword,
        post_keyword: post_keyword
      }),
      unit: unit
    };
  }

  return null;
}
1145958
def run_cmd(input)
      safely do
        command = command_list.match(input)
        return command.new(self, input).execute if command

        puts safe_inspect(multiple_thread_eval(input))
      end
    end
535654
function assembleInput(input) {
  if (_.isArray(input.context)) {
    return input.context;
  }
  var result = (input.prefix || '') + (input.context || '') + (input.suffix || '');
  return strip(result);
}
866
def fetch_command(self, subcommand):
        
        # Get commands outside of try block to prevent swallowing exceptions
        commands = get_commands()
        try:
            app_name = commands[subcommand]
        except KeyError:
            # This might trigger ImproperlyConfigured (masked in get_commands)
            settings.INSTALLED_APPS
            sys.stderr.write("Unknown command: %r\nType '%s help' for usage.\n" %
                (subcommand, self.prog_name))
            sys.exit(1)
        if isinstance(app_name, BaseCommand):
            # If the command is already loaded, use it directly.
            klass = app_name
        else:
            klass = load_command_class(app_name, subcommand)
        return klass