npm-which.js 742 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env node
  2. "use strict"
  3. var program = require('commander');
  4. var pkg = require('../package.json')
  5. var npmWhich = require('../')
  6. program
  7. .version(pkg.version)
  8. .option('-c, --silent', 'No output, just return 0 if any of the executables are found, or 1 if none are found.')
  9. .usage('<command>')
  10. .parse(process.argv)
  11. if (!program.args.length) return program.help()
  12. var cmd = program.args[0]
  13. if (program.silent) {
  14. try {
  15. npmWhich(process.cwd()).sync(cmd)
  16. process.exit(0)
  17. } catch (e) {
  18. if (!e.message.match('not found:')) throw e
  19. process.exit(1)
  20. }
  21. }
  22. try {
  23. console.log(npmWhich(process.cwd()).sync(cmd))
  24. } catch (e) {
  25. if (!e.message.match('not found:')) throw e
  26. console.error('%s not found', cmd)
  27. }