File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env node
2
- jmespath = require ( './jmespath' )
2
+ jmespath = require ( './jmespath' ) ;
3
3
4
- if ( process . argv . length < 3 ) {
4
+ process . stdin . setEncoding ( 'utf-8' ) ;
5
+
6
+
7
+ if ( process . argv . length < 2 ) {
5
8
console . log ( "Must provide a jmespath expression." ) ;
6
9
process . exit ( 1 ) ;
7
10
}
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments