ix-cli 0.0.26 → 0.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/ix-json-filter +26 -9
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b90eae0cfdfe4e66f3d4f00aa6b43cfc79604b298f84b9c8925c28465dce2da
4
- data.tar.gz: 10ce8d8b34502871e1f6996e186969fbfff1e90f8ecd9d65e38987e5ce772921
3
+ metadata.gz: d96878e4367fe4bb7b6732ebef36181393faf9bf99cb936939a0140cc14f2382
4
+ data.tar.gz: 35c9e1ab1970884af9b6852ab3ee8686d9e37956fef09440d0c0d1143fb7bde3
5
5
  SHA512:
6
- metadata.gz: cf573b716a598513a1c7f8e79ef287997094ec29aeb88cd316f035e35cd67492a0953b617606b414ffde36af62ddec4de6c6b2b027ea91881527fa164b4ea8e0
7
- data.tar.gz: 15152f3b4cd5616439218df39bbd4a3a89533b028b70ddf51b6ca415dd7d331dddcc92c2f28293845d01b82375a467d3180d94364eb3aa2b724fea0de40d581b
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[:field]
45
- if json[options[:field]].to_s =~ /#{options[:match]}/
46
- puts line
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
- end
49
- if options[:value]
50
- if json.values.any? { |v| v.to_s =~ /#{options[:match]}/ }
51
- puts line
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ix-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.26
4
+ version: 0.0.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuyoshi Tlacaelel