ix-cli 0.0.26 → 0.0.27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ix-json-filter +26 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d96878e4367fe4bb7b6732ebef36181393faf9bf99cb936939a0140cc14f2382
|
4
|
+
data.tar.gz: 35c9e1ab1970884af9b6852ab3ee8686d9e37956fef09440d0c0d1143fb7bde3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fdac8bfd572c70bb471231c950145bc5d1ed1d6edb95a97a8ec1723bb4f776ebe8ec41c6817ecc272cab265da4c655b52404db425705f8b2c5f5446577bf6ee
|
7
|
+
data.tar.gz: 18b31e415c8e7f2235d0d4f29aebf48cfab503e8a871ab52952179a5b68871f34cb5ac47247748b780edb5b9088f97b065bac326e00b08a5193e7e74a9b59c7d
|
data/bin/ix-json-filter
CHANGED
@@ -5,6 +5,7 @@ require 'json'
|
|
5
5
|
require 'optparse'
|
6
6
|
|
7
7
|
options = {}
|
8
|
+
options[:behavior] = 'add'
|
8
9
|
|
9
10
|
OptionParser.new do |opts|
|
10
11
|
|
@@ -18,14 +19,17 @@ OptionParser.new do |opts|
|
|
18
19
|
options[:field] = value
|
19
20
|
end
|
20
21
|
|
21
|
-
|
22
22
|
opts.on('-m', '--match [REGEX]', 'Match.') do |value|
|
23
23
|
options[:match] = value
|
24
24
|
end
|
25
25
|
|
26
|
+
opts.on('-b', '--behavior [STRING]', 'Behavior can be either [add|remove]') do |value|
|
27
|
+
options[:behavior] = ['add', 'remove'].include?(value) ? value : 'add'
|
28
|
+
end
|
29
|
+
|
26
30
|
end.parse!
|
27
31
|
|
28
|
-
required_options = [:match]
|
32
|
+
required_options = [:match, :behavior]
|
29
33
|
required_options.each do |option|
|
30
34
|
unless options[option]
|
31
35
|
$stderr.puts "Can not run #{option.to_s} was not given."
|
@@ -41,14 +45,27 @@ end
|
|
41
45
|
STDIN.each_line do |line|
|
42
46
|
begin
|
43
47
|
json = JSON.parse(line)
|
44
|
-
if options[:
|
45
|
-
if
|
46
|
-
|
48
|
+
if options[:behavior] == 'add'
|
49
|
+
if options[:field]
|
50
|
+
if json[options[:field]].to_s =~ /#{options[:match]}/
|
51
|
+
puts line
|
52
|
+
end
|
47
53
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
54
|
+
if options[:value]
|
55
|
+
if json.values.any? { |v| v.to_s =~ /#{options[:match]}/ }
|
56
|
+
puts line
|
57
|
+
end
|
58
|
+
end
|
59
|
+
else
|
60
|
+
if options[:field]
|
61
|
+
if json[options[:field]].to_s !~ /#{options[:match]}/
|
62
|
+
puts line
|
63
|
+
end
|
64
|
+
end
|
65
|
+
if options[:value]
|
66
|
+
if json.values.none? { |v| v.to_s =~ /#{options[:match]}/ }
|
67
|
+
puts line
|
68
|
+
end
|
52
69
|
end
|
53
70
|
end
|
54
71
|
rescue JSON::ParserError => e
|