main
|
Last change
on this file was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago |
|
Initial commit
|
-
Property mode
set to
100644
|
|
File size:
733 bytes
|
| Line | |
|---|
| 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) { // if used with -h or --help and no args
|
|---|
| 13 | item = 'help';
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | // cleanse the filename to only contain letters
|
|---|
| 17 | // aka: /\W/g but figured this was eaiser to read
|
|---|
| 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 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.