UNPKG

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