CleverStack/cleverstack-cli

View on GitHub
bin/clever-install

Summary

Maintainability
Test Coverage
#!/usr/bin/env node

var path    = require('path')
  , lib     = GLOBAL.lib = require(path.join(__dirname, '..', 'lib'))
  , program = GLOBAL.program = require('commander')
  , Promise = require('bluebird');

/**  Define CLI Usage
================================*/
program.version(lib.pkg.version)
  .usage('[options] [modules ...]')
  .option('-v, --verbose', 'verbose output useful for debugging');

/**  Define CLI Help
================================*/
program.on('--help', function () {
  console.log('  Examples:');
  console.log('    clever install clever-background-tasks');
  console.log('    clever install clever-background-tasks@0.0.1');
  console.log('');
});

/**  Parse CLI Arguments
================================*/
program.parse(process.argv);
if (program.args.length < 1) {
  program.help();
}

// Tell promise we want long stack traces for easier debugging
Promise.longStackTraces();

/**  Start Installation
================================*/
lib.utils.info('Attempting to install ' + program.args + '...');
lib
  .install
  .run(program.args)
  .then(function() {
    lib.utils.success('Successfully installed.');
    process.exit(0);
  })
  .catch(function(err) {
    lib.utils.fail(err);
    process.exit(1);
  });