bin.js 838 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env node
  2. var rimraf = require('./')
  3. var help = false
  4. var dashdash = false
  5. var args = process.argv.slice(2).filter(function(arg) {
  6. if (dashdash)
  7. return !!arg
  8. else if (arg === '--')
  9. dashdash = true
  10. else if (arg.match(/^(-+|\/)(h(elp)?|\?)$/))
  11. help = true
  12. else
  13. return !!arg
  14. });
  15. if (help || args.length === 0) {
  16. // If they didn't ask for help, then this is not a "success"
  17. var log = help ? console.log : console.error
  18. log('Usage: rimraf <path> [<path> ...]')
  19. log('')
  20. log(' Deletes all files and folders at "path" recursively.')
  21. log('')
  22. log('Options:')
  23. log('')
  24. log(' -h, --help Display this usage info')
  25. process.exit(help ? 0 : 1)
  26. } else
  27. go(0)
  28. function go (n) {
  29. if (n >= args.length)
  30. return
  31. rimraf(args[n], function (er) {
  32. if (er)
  33. throw er
  34. go(n+1)
  35. })
  36. }