1 |
|
/* |
2 |
|
Copyright (c) 2012, Yahoo! Inc. All rights reserved. |
3 |
|
Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. |
4 |
|
*/ |
5 |
|
|
6 |
1 |
var Command = require('./index.js'), |
7 |
|
util = require('util'), |
8 |
|
formatOption = require('../util/help-formatter').formatOption, |
9 |
|
VERSION = require('../../index').VERSION; |
10 |
|
|
11 |
1 |
function HelpCommand() { |
12 |
6 |
Command.call(this); |
13 |
|
} |
14 |
|
|
15 |
1 |
HelpCommand.TYPE = 'help'; |
16 |
1 |
util.inherits(HelpCommand, Command); |
17 |
|
|
18 |
1 |
Command.mix(HelpCommand, { |
19 |
|
synopsis: function () { |
20 |
5 |
return "shows help"; |
21 |
|
}, |
22 |
|
|
23 |
|
usage: function () { |
24 |
|
|
25 |
4 |
console.error('\nUsage: ' + this.toolName() + ' ' + this.type() + ' <command>\n'); |
26 |
4 |
console.error('Available commands are:\n'); |
27 |
|
|
28 |
4 |
var commandObj; |
29 |
4 |
Command.getCommandList().forEach(function (cmd) { |
30 |
20 |
commandObj = Command.create(cmd); |
31 |
20 |
console.error(formatOption(cmd, commandObj.synopsis())); |
32 |
20 |
console.error("\n"); |
33 |
|
}); |
34 |
4 |
console.error("Command names can be abbreviated as long as the abbreviation is unambiguous"); |
35 |
4 |
console.error(this.toolName() + ' version:' + VERSION); |
36 |
4 |
console.error("\n"); |
37 |
|
}, |
38 |
|
run: function (args) { |
39 |
7 |
var command; |
40 |
7 |
if (args.length === 0) { |
41 |
1 |
this.usage(); |
42 |
|
} else { |
43 |
6 |
try { |
44 |
6 |
command = Command.create(args[0]); |
45 |
4 |
command.usage('istanbul', Command.resolveCommandName(args[0])); |
46 |
|
} catch (ex) { |
47 |
2 |
console.error('Invalid command: ' + args[0]); |
48 |
2 |
this.usage(); |
49 |
|
} |
50 |
|
} |
51 |
|
} |
52 |
|
}); |
53 |
|
|
54 |
|
|
55 |
1 |
module.exports = HelpCommand; |
56 |
|
|
57 |
|
|
58 |
|
|