jgrep 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/jgrep +19 -10
  2. data/jgrep.gemspec +1 -1
  3. 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
- raise "Please pass a valid arugment to jgrep" if ARGV == [] || ARGV ==["-s"]
22
- rescue Exception => e
23
- STDERR.puts e
24
- exit 1
25
- end
20
+ expression = nil
26
21
 
27
- begin
28
- json = STDIN.read
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), ARGV.last)
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), ARGV.last)
49
+ result = JGrep::jgrep((json), expression)
41
50
 
42
51
  result.each do |r|
43
52
  options[:field].split(".").each do |node|
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "jgrep"
3
- s.version = "1.0.4"
3
+ s.version = "1.1.0"
4
4
 
5
5
  s.authors = ["P Loubser"]
6
6
  s.date = %q{2011-07-19}
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
+ - 1
7
8
  - 0
8
- - 4
9
- version: 1.0.4
9
+ version: 1.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - P Loubser