lib/flatiron/plugins/cli.js
function executeCommand(parts, callback) {
    var name,
        shouldLoad = true,
        command,
        usage;

    if (typeof parts === 'undefined' || typeof parts === 'function') {
      throw(new Error('parts is a required argument of type Array'));
    }

    name = parts.shift();

    if (app.cli.source || app.commands[name]) {
      if (app.commands[name]) {
        shouldLoad = false;
        if (typeof app.commands[name] != 'function' && !app.commands[name][parts[0]]) {
          shouldLoad = true;
        }
      }

      if (shouldLoad && !loadCommand(name, parts[0])) {
        return callback();
      }

      command = app.commands[name];
      while (command) {
        usage = command.usage;

        if (!app.argv.h && !app.argv.help && typeof command === 'function') {
          while (parts.length + 1 < command.length) {
            parts.push(null);
          }

          if (command.destructive) {
            return ensureDestroy(function (err) {
              return err ? callback() : command.apply(app, parts.concat(callback));
            })
          }

          command.apply(app, parts.concat(callback));
          return;
        }

        command = command[parts.shift()];
      }

      //
      // Since we have not resolved a needle, try and print out a usage message
      //
      if (usage || app.cli.usage) {
        showUsage(usage || app.cli.usage);
        callback(false);
      }
    }
    else if (app.usage) {
      //
      // If there's no directory we're supposed to search for modules, simply
      // print out usage notice if it's provided.
      //
      showUsage(app.cli.usage);
      callback(true);
    }
  }
function executeCommand(parts, callback) {
    var name,
        shouldLoad = true,
        command,
        usage;

    if (typeof parts === 'undefined' || typeof parts === 'function') {
      throw(new Error('parts is a required argument of type Array'));
    }

    name = parts.shift();

    if (app.cli.source || app.commands[name]) {
      if (app.commands[name]) {
        shouldLoad = false;
        if (typeof app.commands[name] != 'function' && !app.commands[name][parts[0]]) {
          shouldLoad = true;
        }
      }

      if (shouldLoad && !loadCommand(name, parts[0])) {
        return callback();
      }

      command = app.commands[name];
      while (command) {
        usage = command.usage;

        if (!app.argv.h && !app.argv.help && typeof command === 'function') {
          while (parts.length + 1 < command.length) {
            parts.push(null);
          }

          if (command.destructive) {
            return ensureDestroy(function (err) {
              return err ? callback() : command.apply(app, parts.concat(callback));
            })
          }

          command.apply(app, parts.concat(callback));
          return;
        }

        command = command[parts.shift()];
      }

      //
      // Since we have not resolved a needle, try and print out a usage message
      //
      if (usage || app.cli.usage) {
        showUsage(usage || app.cli.usage);
        callback(false);
      }
    }
    else if (app.usage) {
      //
      // If there's no directory we're supposed to search for modules, simply
      // print out usage notice if it's provided.
      //
      showUsage(app.cli.usage);
      callback(true);
    }
  }
function executeCommand ( parts , callback ) { var name , shouldLoad = true , command , usage ; if ( typeof parts === 'undefined' || typeof parts === 'function' ) { throw ( new Error ( 'parts is a required argument of type Array' ) ) ; } name = parts . shift ( ) ; if ( app . cli . source || app . commands [ name ] ) { if ( app . commands [ name ] ) { shouldLoad = false ; if ( typeof app . commands [ name ] != 'function' && ! app . commands [ name ] [ parts [ 0 ] ] ) { shouldLoad = true ; } } if ( shouldLoad && ! loadCommand ( name , parts [ 0 ] ) ) { return callback ( ) ; } command = app . commands [ name ] ; while ( command ) { usage = command . usage ; if ( ! app . argv . h && ! app . argv . help && typeof command === 'function' ) { while ( parts . length + 1 < command . length ) { parts . push ( null ) ; } if ( command . destructive ) { return ensureDestroy ( function ( err ) { return err ? callback ( ) : command . apply ( app , parts . concat ( callback ) ) ; } ) } command . apply ( app , parts . concat ( callback ) ) ; return ; } command = command [ parts . shift ( ) ] ; } // // Since we have not resolved a needle, try and print out a usage message // if ( usage || app . cli . usage ) { showUsage ( usage || app . cli . usage ) ; callback ( false ) ; } } else if ( app . usage ) { // // If there's no directory we're supposed to search for modules, simply // print out usage notice if it's provided. // showUsage ( app . cli . usage ) ; callback ( true ) ; } }
Helper function which executes the command represented by the Array of `parts` passing control to the `callback`.
Helper function which executes the command represented by the Array of parts passing control to the callback .