lib/autocomplete.js
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;
}
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;
}
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 ; }
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
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 .