-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·46 lines (36 loc) · 941 Bytes
/
cli.js
File metadata and controls
executable file
·46 lines (36 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env node
import process from 'node:process';
import meow from 'meow';
import binaryVersion from 'binary-version';
const cli = meow(`
Usage
$ binary-version <binary> [arguments]
The arguments default to \`--version\`
Exits with code 2 if no version could be found
Examples
$ curl --version
curl 7.30.0 (x86_64-apple-darwin13.0)
$ binary-version curl
7.30.0
$ openssl version
OpenSSL 1.0.2p 14 Aug 2018
$ binary-version openssl version
1.0.2
`, {
importMeta: import.meta,
});
const [binary, ...binaryArguments] = cli.input;
if (!binary && process.stdin.isTTY) {
console.error('Binary name required');
process.exit(1);
}
const options = {};
if (binaryArguments.length > 0) {
options.args = binaryArguments;
}
const version = await binaryVersion(binary, options);
if (!version) {
console.error(`Could not find a version for \`${binary}\``);
process.exit(2);
}
console.log(version);