Skip to content

Commit 5138bed

Browse files
richardgarnierisaacs
authored andcommitted
patch for #149
1 parent 8fff305 commit 5138bed

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

bin/semver

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,29 @@ var argv = process.argv.slice(2)
1616
, semver = require("../semver")
1717
, reverse = false
1818

19-
main()
19+
preMain()
2020

21-
function main () {
22-
if (!argv.length) return help()
21+
function preMain() {
22+
if (!process.stdin.isTTY) {
23+
process.stdin.setEncoding('utf8');
24+
25+
process.stdin.on('readable', function() {
26+
var chunk = process.stdin.read();
27+
if (chunk !== null) {
28+
versions = versions.concat(chunk.split(/\s/));
29+
}
30+
});
31+
32+
process.stdin.on('end', () => {
33+
main(versions.length !== 0);
34+
});
35+
} else {
36+
main(false);
37+
}
38+
}
39+
40+
function main (piped) {
41+
if (!argv.length && !piped) return help()
2342
while (argv.length) {
2443
var a = argv.shift()
2544
var i = a.indexOf('=')
@@ -56,6 +75,7 @@ function main () {
5675
break
5776
case "-h": case "--help": case "-?":
5877
return help()
78+
break
5979
default:
6080
versions.push(a)
6181
break

0 commit comments

Comments
 (0)