cli.js 674 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env node
  2. 'use strict';
  3. var pkg = require('./package.json');
  4. var repeating = require('./');
  5. var argv = process.argv.slice(2);
  6. function help() {
  7. console.log([
  8. '',
  9. ' ' + pkg.description,
  10. '',
  11. ' Usage',
  12. ' $ repeating <string> <count>',
  13. '',
  14. ' Example',
  15. ' $ repeating \'unicorn \' 2',
  16. ' unicorn unicorn'
  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 (!argv[1]) {
  28. console.error('You have to define how many times to repeat the string.');
  29. process.exit(1);
  30. }
  31. console.log(repeating(argv[0], Number(argv[1])));