1 | #!/usr/bin/env node
|
2 |
|
3 | "use strict"
|
4 |
|
5 | var program = require('commander');
|
6 | var pkg = require('../package.json')
|
7 |
|
8 | var npmWhich = require('../')
|
9 |
|
10 | program
|
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 |
|
16 | if (!program.args.length) return program.help()
|
17 |
|
18 | var cmd = program.args[0]
|
19 |
|
20 | if (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 |
|
30 | try {
|
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 | }
|