You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
759 B

7 years ago
  1. #!/usr/bin/env node
  2. var argv = require('optimist')
  3. .usage('Count the lines in a file.\nUsage: $0')
  4. .wrap(80)
  5. .demand('f')
  6. .alias('f', [ 'file', 'filename' ])
  7. .describe('f',
  8. "Load a file. It's pretty important."
  9. + " Required even. So you'd better specify it."
  10. )
  11. .alias('b', 'base')
  12. .describe('b', 'Numeric base to display the number of lines in')
  13. .default('b', 10)
  14. .describe('x', 'Super-secret optional parameter which is secret')
  15. .default('x', '')
  16. .argv
  17. ;
  18. var fs = require('fs');
  19. var s = fs.createReadStream(argv.file);
  20. var lines = 0;
  21. s.on('data', function (buf) {
  22. lines += buf.toString().match(/\n/g).length;
  23. });
  24. s.on('end', function () {
  25. console.log(lines.toString(argv.base));
  26. });