CleverStack/cleverstack-cli

View on GitHub
bin/clever-search

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');

program.version(lib.pkg.version);

program.on('--help', function() {
  console.log('  Examples:');
  console.log('    clever search users');
  console.log('    clever search users auth email');
  console.log('');
});

program.parse(process.argv);

// args void of initial commands
var args = process.argv.slice(2);

if (!args) {
  program.help();
}

lib
.search
.aggregate(args)
.spread(function(npm, bower) {
  var repos = npm.concat(bower);

  if (repos.length < 1) {
    lib.utils.fail('Couldn\'t find any modules that were compatible with CleverStack.');
  }

  lib.utils.success('Found ' + repos.length + ' module' + (repos.length !== 1 ? 's' : ''));
  console.log('');

  repos.forEach(lib.repos.display);
  process.exit(0);
})
.catch(function(err) {
  lib.utils.fail(err);
});