Various updates.

This commit is contained in:
Julien Fontanet 2014-05-24 17:09:10 +02:00
parent 29398b9869
commit 84e6228f90
3 changed files with 29 additions and 38 deletions

View File

@ -4,4 +4,4 @@
//==================================================================== //====================================================================
require('../')(process.argv.slice(2)); require('exec-promise')(require('..'));

View File

@ -23,20 +23,21 @@
"url": "https://github.com/vatesfr/xo-cli" "url": "https://github.com/vatesfr/xo-cli"
}, },
"dependencies": { "dependencies": {
"bluebird": "^1.1.0", "bluebird": "^1.2.4",
"chalk": "^0.4.0", "chalk": "^0.4.0",
"inquirer": "^0.4.1", "exec-promise": "^0.2.4",
"l33teral": "^2.0.3", "inquirer": "^0.5.0",
"l33teral": "^2.0.4",
"lodash": "^2.4.1", "lodash": "^2.4.1",
"mkdirp": "^0.3.5", "mkdirp": "^0.5.0",
"nomnom": "^1.6.2", "nomnom": "^1.6.2",
"ws": "^0.4.31", "ws": "^0.4.31",
"xdg": "^0.1.1" "xdg": "^0.1.1"
}, },
"devDependencies": { "devDependencies": {
"chai": "^1.9.0", "chai": "^1.9.1",
"human-format": "^0.1.0", "human-format": "^0.1.3",
"mocha": "^1.18.0", "mocha": "^1.19.0",
"mocha-promise": "0.0.1" "mocha-promise": "0.0.1"
}, },
"scripts": { "scripts": {

View File

@ -3,7 +3,7 @@
//==================================================================== //====================================================================
var _ = require('lodash'); var _ = require('lodash');
var nomnom = require('nomnom'); var nomnom = require('nomnom')();
var Promise = require('bluebird'); var Promise = require('bluebird');
//-------------------------------------------------------------------- //--------------------------------------------------------------------
@ -14,6 +14,15 @@ var Xo = require('./xo');
//==================================================================== //====================================================================
//`nomnom.print()` version which does not use `process.exit()`.
nomnom.print = function (str, code) {
throw ''+ str;
// TODO: handles code.
};
//====================================================================
var connect = function () { var connect = function () {
return config.load().bind({}).then(function (config) { return config.load().bind({}).then(function (config) {
if (!config.server) if (!config.server)
@ -180,7 +189,9 @@ module.exports = function (argv) {
}, },
}, function (opts) { }, function (opts) {
return connect().then(function (xo) { return connect().then(function (xo) {
return xo.send('system.methodSignature', {name: opts.name}).then(console.log); return xo.send('system.methodSignature', {
name: opts.name
}).then(console.log);
}); });
}); });
@ -203,40 +214,19 @@ module.exports = function (argv) {
}); });
// TODO: handle global `--config FILE` option. // TODO: handle global `--config FILE` option.
nomnom var opts = nomnom
.option('version', { .option('version', {
flag: true, flag: true,
help: 'prints the current version of xo-cli', help: 'prints the current version of xo-cli',
callback: function () {
return 'xo-cli version '+ require('../package').version;
},
}) })
.parse(argv) .parse(argv)
; ;
if (opts.version)
{
return 'xo-cli version '+ require('../package').version;
}
// Executes the selected command. // Executes the selected command.
Promise.try(command, [commandOpts]).then(function (value) { return command(commandOpts);
if (_.isString(value))
{
console.log(value);
}
process.exit(0);
}).catch(function (error) {
if (error === undefined)
{
// Nothing to do.
undefined;
}
else if (_.isNumber(error))
{
process.exit(error);
}
else
{
console.error(error.stack || error);
}
process.exit(1);
});
}; };