Skip to content

Commit dee99af

Browse files
authored
support silent output (#23)
1 parent 7e95af8 commit dee99af

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

bin/detect-port

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const pkg = require('../package');
77
const args = process.argv.slice(2);
88
const arg_0 = args[0];
99

10-
if (!!~['-v', '--version'].indexOf(arg_0)) {
10+
if (arg_0 && !!~['-v', '--version'].indexOf(arg_0.toLowerCase())) {
1111
console.log(pkg.version);
1212
process.exit(0);
1313
}
@@ -35,22 +35,30 @@ if (!arg_0) {
3535
console.log();
3636
console.log(' Options:');
3737
console.log();
38-
console.log(' -v, --version show version and exit');
38+
console.log(' -v, --version output version and exit');
39+
console.log(' -s, --silent output port without verbose log');
3940
console.log(' -h, --help output usage information');
4041
console.log();
4142
console.log(' Further help:');
4243
console.log();
4344
console.log(` ${pkg.homepage}`);
4445
console.log();
4546
} else {
47+
const isSilent = !!~process.argv.indexOf('-s') || !!~process.argv.indexOf('--silent');
48+
4649
main(port, (err, _port) => {
47-
if (err) {
48-
console.log(`get available port failed with ${err}`);
49-
}
50+
if (isSilent) {
51+
console.log(_port || port);
52+
} else {
53+
if (err) {
54+
console.log(`get available port failed with ${err}`);
55+
}
56+
57+
if (port !== _port) {
58+
console.log(`port ${port} was occupied`);
59+
}
5060

51-
if (port !== _port) {
52-
console.log(`port ${port} was occupied`);
61+
console.log(`get available port ${_port}`);
5362
}
54-
console.log(`get available port ${_port}`);
5563
});
5664
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "detect-port",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"description": "detect available port",
55
"keywords": [
66
"detect",

0 commit comments

Comments
 (0)