Skip to content

Commit cd4a1e2

Browse files
committed
Modify jp command to read input from stdin
Consistent with other jmespath implementations.
1 parent 847809c commit cd4a1e2

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

jp.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
#!/usr/bin/env node
2-
jmespath = require('./jmespath')
2+
jmespath = require('./jmespath');
33

4-
if (process.argv.length < 3) {
4+
process.stdin.setEncoding('utf-8');
5+
6+
7+
if (process.argv.length < 2) {
58
console.log("Must provide a jmespath expression.");
69
process.exit(1);
710
}
8-
jmespath.compile(process.argv[2]);
9-
console.log(JSON.stringify(jmespath.compile(process.argv[2]), null, 2));
10-
console.log(JSON.stringify(jmespath.search(JSON.parse(process.argv[3]), process.argv[2])));
11+
var inputJSON = "";
12+
13+
process.stdin.on('readable', function() {
14+
var chunk = process.stdin.read();
15+
if (chunk !== null) {
16+
inputJSON += chunk;
17+
}
18+
});
19+
20+
process.stdin.on('end', function() {
21+
var parsedInput = JSON.parse(inputJSON);
22+
console.log(JSON.stringify(jmespath.search(parsedInput, process.argv[2])));
23+
});

0 commit comments

Comments
 (0)