1#!/usr/bin/env node 2 3var rimraf = require('./') 4 5var help = false 6var dashdash = false 7var noglob = false 8var args = process.argv.slice(2).filter(function(arg) { 9 if (dashdash) 10 return !!arg 11 else if (arg === '--') 12 dashdash = true 13 else if (arg === '--no-glob' || arg === '-G') 14 noglob = true 15 else if (arg === '--glob' || arg === '-g') 16 noglob = false 17 else if (arg.match(/^(-+|\/)(h(elp)?|\?)$/)) 18 help = true 19 else 20 return !!arg 21}) 22 23if (help || args.length === 0) { 24 // If they didn't ask for help, then this is not a "success" 25 var log = help ? console.log : console.error 26 log('Usage: rimraf <path> [<path> ...]') 27 log('') 28 log(' Deletes all files and folders at "path" recursively.') 29 log('') 30 log('Options:') 31 log('') 32 log(' -h, --help Display this usage info') 33 log(' -G, --no-glob Do not expand glob patterns in arguments') 34 log(' -g, --glob Expand glob patterns in arguments (default)') 35 process.exit(help ? 0 : 1) 36} else 37 go(0) 38 39function go (n) { 40 if (n >= args.length) 41 return 42 var options = {} 43 if (noglob) 44 options = { glob: false } 45 rimraf(args[n], options, function (er) { 46 if (er) 47 throw er 48 go(n+1) 49 }) 50} 51