index.js
function main (processArgv, conf) {

  // CLI input
  var opts = getOpts(processArgv);
  var argv = opts.argv;

  // Update notifier
  if (!argv["no-notifier"]) {
    checkUpdate();
  }

  // Convert options "--help" and "-h" into command "help"
  if (argv.help) {
    processArgv = transformHelpArgs(processArgv);
    // Regenerate opts from newly forged process.argv
    opts = getOpts(processArgv);
    argv = opts.argv;
  }

  // "--version"
  if (argv.version) {
    showVersion();
  }

  var commandName = argv._[0];

  // Demand command name
  if (!commandName) {
    console.error("No command specified");
    opts.showHelp();
    process.exit(127);
  }

  // Load command module
  var command = commands.load(commandName);

  // Demand valid command
  if (!command) {
    console.error("Unknown command: " + commandName);
    opts.showHelp();
    process.exit(127);
  }

  process.on("exit", function () {
    ttys.stdin.end();
  });

  // Configure opts and run command (inside a domain to catch any error)
  commands.run(command, opts, conf).then(ok, fail);

  function ok () {
    process.exit(0);
  }

  function fail (e) {
    if (e.code === "EINTERRUPT") {
      process.exit(127);
    } else {
      console.error("%s", e);
      if (process.env.DEBUG) {
        throw e;
      }
      process.exit(1);
    }
  }
}
function main (processArgv, conf) {

  // CLI input
  var opts = getOpts(processArgv);
  var argv = opts.argv;

  // Update notifier
  if (!argv["no-notifier"]) {
    checkUpdate();
  }

  // Convert options "--help" and "-h" into command "help"
  if (argv.help) {
    processArgv = transformHelpArgs(processArgv);
    // Regenerate opts from newly forged process.argv
    opts = getOpts(processArgv);
    argv = opts.argv;
  }

  // "--version"
  if (argv.version) {
    showVersion();
  }

  var commandName = argv._[0];

  // Demand command name
  if (!commandName) {
    console.error("No command specified");
    opts.showHelp();
    process.exit(127);
  }

  // Load command module
  var command = commands.load(commandName);

  // Demand valid command
  if (!command) {
    console.error("Unknown command: " + commandName);
    opts.showHelp();
    process.exit(127);
  }

  process.on("exit", function () {
    ttys.stdin.end();
  });

  // Configure opts and run command (inside a domain to catch any error)
  commands.run(command, opts, conf).then(ok, fail);

  function ok () {
    process.exit(0);
  }

  function fail (e) {
    if (e.code === "EINTERRUPT") {
      process.exit(127);
    } else {
      console.error("%s", e);
      if (process.env.DEBUG) {
        throw e;
      }
      process.exit(1);
    }
  }
}
function main ( processArgv , conf ) { // CLI input var opts = getOpts ( processArgv ) ; var argv = opts . argv ; // Update notifier if ( ! argv [ "no-notifier" ] ) { checkUpdate ( ) ; } // Convert options "--help" and "-h" into command "help" if ( argv . help ) { processArgv = transformHelpArgs ( processArgv ) ; // Regenerate opts from newly forged process.argv opts = getOpts ( processArgv ) ; argv = opts . argv ; } // "--version" if ( argv . version ) { showVersion ( ) ; } var commandName = argv . _ [ 0 ] ; // Demand command name if ( ! commandName ) { console . error ( "No command specified" ) ; opts . showHelp ( ) ; process . exit ( 127 ) ; } // Load command module var command = commands . load ( commandName ) ; // Demand valid command if ( ! command ) { console . error ( "Unknown command: " + commandName ) ; opts . showHelp ( ) ; process . exit ( 127 ) ; } process . on ( "exit" , function ( ) { ttys . stdin . end ( ) ; } ) ; // Configure opts and run command (inside a domain to catch any error) commands . run ( command , opts , conf ) . then ( ok , fail ) ; function ok ( ) { process . exit ( 0 ) ; } function fail ( e ) { if ( e . code === "EINTERRUPT" ) { process . exit ( 127 ) ; } else { console . error ( "%s" , e ) ; if ( process . env . DEBUG ) { throw e ; } process . exit ( 1 ) ; } } }
Main execution, after env has been checked
Main execution after env has been checked