index.js 733 B

123456789101112131415161718192021222324252627
  1. var fs = require('fs');
  2. var path = require('path');
  3. const supportsColor = require('supports-color');
  4. module.exports = help;
  5. const highlight = supportsColor.stdout ? '\x1B\[$1m' : '';
  6. function help(item) {
  7. if (!item) {
  8. item = 'help';
  9. } else if (item === true) { // if used with -h or --help and no args
  10. item = 'help';
  11. }
  12. // cleanse the filename to only contain letters
  13. // aka: /\W/g but figured this was eaiser to read
  14. item = item.replace(/[^a-z]/gi, '');
  15. try {
  16. var dir = path.join(__dirname, '..', '..', 'doc', 'cli', item + '.txt');
  17. var body = fs.readFileSync(dir, 'utf8');
  18. return body.replace(/\\x1B\[(.)m/g, highlight);
  19. } catch (e) {
  20. return '"' + item + '" help can\'t be found';
  21. }
  22. }