cli.js 775 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env node
  2. 'use strict';
  3. var fs = require('fs');
  4. var pkg = require('./package.json');
  5. var strip = require('./');
  6. var input = process.argv[2];
  7. function help() {
  8. console.log([
  9. pkg.description,
  10. '',
  11. 'Usage',
  12. ' $ strip-ansi <input-file> > <output-file>',
  13. ' $ cat <input-file> | strip-ansi > <output-file>',
  14. '',
  15. 'Example',
  16. ' $ strip-ansi unicorn.txt > unicorn-stripped.txt'
  17. ].join('\n'));
  18. }
  19. if (process.argv.indexOf('--help') !== -1) {
  20. help();
  21. return;
  22. }
  23. if (process.argv.indexOf('--version') !== -1) {
  24. console.log(pkg.version);
  25. return;
  26. }
  27. if (input) {
  28. process.stdout.write(strip(fs.readFileSync(input, 'utf8')));
  29. return;
  30. }
  31. process.stdin.setEncoding('utf8');
  32. process.stdin.on('data', function (data) {
  33. process.stdout.write(strip(data));
  34. });