UNPKG

975 BJavaScriptView Raw
1var Q = require('q');
2var path = require('path');
3var fs = require('../util/fs');
4var createError = require('../util/createError');
5
6function help(logger, name, config) {
7 var json;
8
9 if (name) {
10 json = path.resolve(
11 __dirname,
12 '../templates/json/help-' + name.replace(/\s+/g, '/') + '.json'
13 );
14 } else {
15 json = path.resolve(__dirname, '../templates/json/help.json');
16 }
17
18 return Q.promise(function(resolve) {
19 fs.exists(json, resolve);
20 }).then(function(exists) {
21 if (!exists) {
22 throw createError('Unknown command: ' + name, 'EUNKNOWNCMD', {
23 command: name
24 });
25 }
26
27 return require(json);
28 });
29}
30
31// -------------------
32
33help.readOptions = function(argv) {
34 var cli = require('../util/cli');
35 var options = cli.readOptions(argv);
36 var name = options.argv.remain.slice(1).join(' ');
37
38 return [name];
39};
40
41module.exports = help;