1 | var fs = require('fs');
|
2 | var path = require('path');
|
3 | const supportsColor = require('supports-color');
|
4 |
|
5 | module.exports = help;
|
6 |
|
7 | const highlight = supportsColor.stdout ? '\x1B\[$1m' : '';
|
8 |
|
9 | function help(item) {
|
10 | if (!item) {
|
11 | item = 'help';
|
12 | } else if (item === true) {
|
13 | item = 'help';
|
14 | }
|
15 |
|
16 |
|
17 |
|
18 | item = item.replace(/[^a-z]/gi, '');
|
19 |
|
20 | try {
|
21 | var dir = path.join(__dirname, '..', '..', 'doc', 'cli', item + '.txt');
|
22 | var body = fs.readFileSync(dir, 'utf8');
|
23 | return body.replace(/\\x1B\[(.)m/g, highlight);
|
24 | } catch (e) {
|
25 | return '"' + item + '" help can\'t be found';
|
26 | }
|
27 | }
|