main
|
Last change
on this file since 8ca35dc was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 18 months ago |
|
Initial commit
|
-
Property mode
set to
100644
|
|
File size:
985 bytes
|
| Line | |
|---|
| 1 | #!/usr/bin/env node
|
|---|
| 2 | var which = require("../")
|
|---|
| 3 | if (process.argv.length < 3)
|
|---|
| 4 | usage()
|
|---|
| 5 |
|
|---|
| 6 | function usage () {
|
|---|
| 7 | console.error('usage: which [-as] program ...')
|
|---|
| 8 | process.exit(1)
|
|---|
| 9 | }
|
|---|
| 10 |
|
|---|
| 11 | var all = false
|
|---|
| 12 | var silent = false
|
|---|
| 13 | var dashdash = false
|
|---|
| 14 | var args = process.argv.slice(2).filter(function (arg) {
|
|---|
| 15 | if (dashdash || !/^-/.test(arg))
|
|---|
| 16 | return true
|
|---|
| 17 |
|
|---|
| 18 | if (arg === '--') {
|
|---|
| 19 | dashdash = true
|
|---|
| 20 | return false
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | var flags = arg.substr(1).split('')
|
|---|
| 24 | for (var f = 0; f < flags.length; f++) {
|
|---|
| 25 | var flag = flags[f]
|
|---|
| 26 | switch (flag) {
|
|---|
| 27 | case 's':
|
|---|
| 28 | silent = true
|
|---|
| 29 | break
|
|---|
| 30 | case 'a':
|
|---|
| 31 | all = true
|
|---|
| 32 | break
|
|---|
| 33 | default:
|
|---|
| 34 | console.error('which: illegal option -- ' + flag)
|
|---|
| 35 | usage()
|
|---|
| 36 | }
|
|---|
| 37 | }
|
|---|
| 38 | return false
|
|---|
| 39 | })
|
|---|
| 40 |
|
|---|
| 41 | process.exit(args.reduce(function (pv, current) {
|
|---|
| 42 | try {
|
|---|
| 43 | var f = which.sync(current, { all: all })
|
|---|
| 44 | if (all)
|
|---|
| 45 | f = f.join('\n')
|
|---|
| 46 | if (!silent)
|
|---|
| 47 | console.log(f)
|
|---|
| 48 | return pv;
|
|---|
| 49 | } catch (e) {
|
|---|
| 50 | return 1;
|
|---|
| 51 | }
|
|---|
| 52 | }, 0))
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.