2015-02-26 15:47:56 +00:00
|
|
|
(function() {
|
2015-08-13 12:11:58 +00:00
|
|
|
var _, capitano, columnify, command, general, indent, parse, print;
|
2015-02-26 15:47:56 +00:00
|
|
|
|
|
|
|
_ = require('lodash');
|
|
|
|
|
|
|
|
_.str = require('underscore.string');
|
|
|
|
|
|
|
|
capitano = require('capitano');
|
|
|
|
|
2015-08-13 12:11:58 +00:00
|
|
|
columnify = require('columnify');
|
2015-02-26 15:47:56 +00:00
|
|
|
|
2015-08-13 12:11:58 +00:00
|
|
|
parse = function(object) {
|
|
|
|
return _.object(_.map(object, function(item) {
|
|
|
|
var signature;
|
|
|
|
if (item.alias != null) {
|
|
|
|
signature = item.toString();
|
|
|
|
} else {
|
|
|
|
signature = item.signature.toString();
|
2015-02-26 15:47:56 +00:00
|
|
|
}
|
2015-08-13 12:11:58 +00:00
|
|
|
return [signature, item.description];
|
|
|
|
}));
|
2015-02-26 15:47:56 +00:00
|
|
|
};
|
|
|
|
|
2015-08-13 12:11:58 +00:00
|
|
|
indent = function(text) {
|
|
|
|
text = _.map(_.str.lines(text), function(line) {
|
|
|
|
return ' ' + line;
|
2015-02-26 15:47:56 +00:00
|
|
|
});
|
2015-08-13 12:11:58 +00:00
|
|
|
return text.join('\n');
|
2015-02-26 15:47:56 +00:00
|
|
|
};
|
|
|
|
|
2015-08-13 12:11:58 +00:00
|
|
|
print = function(data) {
|
|
|
|
return console.log(indent(columnify(data, {
|
|
|
|
showHeaders: false,
|
|
|
|
minWidth: 35
|
|
|
|
})));
|
2015-02-26 15:47:56 +00:00
|
|
|
};
|
|
|
|
|
2015-08-13 12:11:58 +00:00
|
|
|
general = function(params, options, done) {
|
|
|
|
var commands;
|
2015-02-26 15:47:56 +00:00
|
|
|
console.log('Usage: resin [COMMAND] [OPTIONS]\n');
|
|
|
|
console.log('Commands:\n');
|
2015-08-13 12:11:58 +00:00
|
|
|
commands = _.reject(capitano.state.commands, function(command) {
|
|
|
|
return command.isWildcard();
|
|
|
|
});
|
|
|
|
print(parse(commands));
|
2015-08-12 12:17:46 +00:00
|
|
|
if (!_.isEmpty(capitano.state.globalOptions)) {
|
|
|
|
console.log('\nGlobal Options:\n');
|
2015-08-13 12:11:58 +00:00
|
|
|
print(parse(capitano.state.globalOptions));
|
2015-08-12 12:17:46 +00:00
|
|
|
}
|
2015-08-13 12:11:58 +00:00
|
|
|
return done();
|
2015-02-26 15:47:56 +00:00
|
|
|
};
|
|
|
|
|
2015-03-03 14:14:16 +00:00
|
|
|
command = function(params, options, done) {
|
2015-02-26 15:47:56 +00:00
|
|
|
return capitano.state.getMatchCommand(params.command, function(error, command) {
|
|
|
|
if (error != null) {
|
|
|
|
return done(error);
|
|
|
|
}
|
|
|
|
if ((command == null) || command.isWildcard()) {
|
2015-08-13 12:11:58 +00:00
|
|
|
return done(new Error("Command not found: " + params.command));
|
2015-02-26 15:47:56 +00:00
|
|
|
}
|
|
|
|
console.log("Usage: " + command.signature);
|
|
|
|
if (command.help != null) {
|
|
|
|
console.log("\n" + command.help);
|
|
|
|
} else if (command.description != null) {
|
|
|
|
console.log("\n" + (_.str.humanize(command.description)));
|
|
|
|
}
|
|
|
|
if (!_.isEmpty(command.options)) {
|
|
|
|
console.log('\nOptions:\n');
|
2015-08-13 12:11:58 +00:00
|
|
|
print(parse(command.options));
|
2015-02-26 15:47:56 +00:00
|
|
|
}
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.help = {
|
|
|
|
signature: 'help [command...]',
|
|
|
|
description: 'show help',
|
2015-03-03 14:14:16 +00:00
|
|
|
help: 'Get detailed help for an specific command.\n\nExamples:\n\n $ resin help apps\n $ resin help os download',
|
2015-02-26 15:47:56 +00:00
|
|
|
action: function(params, options, done) {
|
|
|
|
if (params.command != null) {
|
2015-03-03 14:14:16 +00:00
|
|
|
return command(params, options, done);
|
2015-02-26 15:47:56 +00:00
|
|
|
} else {
|
2015-03-03 14:14:16 +00:00
|
|
|
return general(params, options, done);
|
2015-02-26 15:47:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}).call(this);
|