jgrep 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/jgrep +19 -10
- data/jgrep.gemspec +1 -1
- metadata +2 -2
data/bin/jgrep
CHANGED
@@ -16,19 +16,28 @@ OptionParser.new do |opts|
|
|
16
16
|
|
17
17
|
end.parse!
|
18
18
|
|
19
|
-
|
20
19
|
begin
|
21
|
-
|
22
|
-
rescue Exception => e
|
23
|
-
STDERR.puts e
|
24
|
-
exit 1
|
25
|
-
end
|
20
|
+
expression = nil
|
26
21
|
|
27
|
-
|
28
|
-
|
22
|
+
ARGV.each do |argument|
|
23
|
+
if argument =~ /<|>|=/
|
24
|
+
expression = argument
|
25
|
+
ARGV.delete(argument)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
unless STDIN.tty?
|
30
|
+
json = STDIN.read
|
31
|
+
else
|
32
|
+
if ARGV.size == 1
|
33
|
+
json = File.read(ARGV.first)
|
34
|
+
else
|
35
|
+
raise "No json input specified"
|
36
|
+
end
|
37
|
+
end
|
29
38
|
|
30
39
|
unless options[:field]
|
31
|
-
result = JGrep::jgrep((json),
|
40
|
+
result = JGrep::jgrep((json), expression)
|
32
41
|
unless result == "[]"
|
33
42
|
(options[:flat] == false) ? puts(JSON.pretty_generate(result)) : puts(result.to_json)
|
34
43
|
end
|
@@ -37,7 +46,7 @@ begin
|
|
37
46
|
raise "'-s' flag requires a field to display"
|
38
47
|
end
|
39
48
|
|
40
|
-
result = JGrep::jgrep((json),
|
49
|
+
result = JGrep::jgrep((json), expression)
|
41
50
|
|
42
51
|
result.each do |r|
|
43
52
|
options[:field].split(".").each do |node|
|
data/jgrep.gemspec
CHANGED