jr-cli 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fbe53abe97c6501e6e1d78f1bfdded7ef8cfd97
4
- data.tar.gz: 3cd6173a84e84c40e856c56a7638197f3764d9f9
3
+ metadata.gz: bf4bfddefb27afc5dbc464a2ae44bbc536dadd0d
4
+ data.tar.gz: 3af064b0674b03eccd4ea025f4d70e956e75e8ad
5
5
  SHA512:
6
- metadata.gz: 23149a324db87a7cc6dee03e34bdde6f30d679c69fd77c73ec9f37f7cb93205e2a01bf8a1c6c65640ea3f8e5f9a7a6584f8ed6c30d734ae59d9ca27e58b99396
7
- data.tar.gz: a3e3aebf4c2ae87f9e80dc4bd4ff76127ba27c8bfb34ea67386af1c2c6ca21c7fe9651badaa6b275ad19f3d959fcf3d7413eccf704ffe533a148c2b82281ca1c
6
+ metadata.gz: 31956edb39542e71796909a3b3c5c817f1b2073f1c98573deaf5ddc5a3835041e5708daeee7495dd0639db64cb7bd8f421f85b36e294c2522f32095b453ba915
7
+ data.tar.gz: 64e5a7e4249d42a2567e57f664d28427454c7c5ec0e9b1407903a7db9bc50463238807c74b7f0fd1903b98006044d51d4dda26ef7e0f6a17f99b613f36757c77
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.3.0 (2015-08-28)
2
+
3
+ * Add `--raw-input` option
4
+ * Add `--color-output` option
5
+ * Add `--monochrome-output` option
6
+ * Do indentation when filter is omitted
7
+
1
8
  ## 0.2.0 (2015-08-19)
2
9
 
3
10
  * [BREAKING CHANGE] Now `-r` is alias for `--raw-output` and use `--require` to require library
data/README.md CHANGED
@@ -34,9 +34,12 @@ You can also read JSON not from files but from STDIN.
34
34
  ```
35
35
  --require FILE require the FILE before execution
36
36
  -c, --compact-output output each JSON in single line
37
+ -f, --from-file FILE read filter from file
37
38
  -r, --raw-output output strings as raw output
39
+ -R, --raw-input read each line as string
38
40
  -C, --color-output output with colors even if writing to a pipe or a file
39
41
  -M, --monochrome-output output without colors
42
+ -n, --null-input use null as input instead of any files
40
43
  ```
41
44
 
42
45
  ## jr filter tutorial
@@ -64,7 +67,7 @@ $ jr 'unwrap' repos.json
64
67
  `Enumerable` has many useful methods and you can transform data with them.
65
68
 
66
69
  ```
67
- $j r 'unwrap.group_by(&:language).map{|k, v| [k, v.size] }.sort_by{|k, v| -v }' repos.json
70
+ $ jr 'unwrap.group_by(&:language).map{|k, v| [k, v.size] }.sort_by{|k, v| -v }' repos.json
68
71
  [
69
72
  "Ruby",
70
73
  28
data/bin/jr CHANGED
@@ -10,28 +10,58 @@ opt = OptionParser.new
10
10
  opt.banner = "jr - Command-line JSON processor for Rubyists [Ver. #{Jr::Cli::VERSION}]\n\n" +
11
11
  "Usage: jr [options] <jr filter> [file...]"
12
12
  opt.version = Jr::Cli::VERSION
13
- opt.on('--require FILE', 'require the FILE before execution') {|file| require file }
13
+ opt.on('--require FILE', 'require the FILE before execution') { |file| require file }
14
14
  pretty = true
15
- opt.on('-c', '--compact-output', 'output each JSON in single line') { pretty = false }
15
+ opt.on('-c', '--compact-output', 'output each JSON in single line') { pretty = false }
16
+ from_file = false
17
+ filter_file = nil
18
+ opt.on('-f', '--from-file FILE', 'read filter from file') { |file| from_file = true; filter_file = file }
16
19
  raw_output = false
17
- opt.on('-r', '--raw-output', 'output strings as raw output') { raw_output = true }
20
+ opt.on('-r', '--raw-output', 'output strings as raw output') { raw_output = true }
21
+ raw_input = false
22
+ opt.on('-R', '--raw-input', 'read each line as string') { raw_input = true }
18
23
  color_output = STDOUT.tty?
19
- opt.on('--color-output', '-C', 'output with colors even if writing to a pipe or a file') { color_output = true }
20
- opt.on('--monochrome-output', '-M', 'output without colors') { color_output = false }
24
+ opt.on('-C', '--color-output', 'output with colors even if writing to a pipe or a file') { color_output = true }
25
+ opt.on('-M', '--monochrome-output', 'output without colors') { color_output = false }
26
+ null_input = false
27
+ opt.on('-n', '--null-input', 'use null as input instead of any files') { null_input = true }
21
28
  opt.parse! ARGV
22
29
 
23
30
  require 'jr/cli/core_ext'
24
31
 
25
32
  trap('INT') { exit 130 }
26
33
 
27
- inputs = ARGV[1] ? ARGV[1..-1].map {|f| open f } : [STDIN]
28
- result = Enumerator.new do |yielder|
29
- inputs.each do |input|
30
- Yajl::Parser.new(symbolize_keys: true).parse(input) do |d|
31
- yielder.yield d
32
- end
34
+ if from_file
35
+ inputs = ARGV[0] ? ARGV[0..-1].map {|f| open f } : [STDIN]
36
+ jr_filter = open(filter_file).read
37
+ else
38
+ inputs = ARGV[1] ? ARGV[1..-1].map {|f| open f } : [STDIN]
39
+ jr_filter = ARGV[0] || 'self'
40
+ end
41
+
42
+ if null_input
43
+ input_enumerator = [nil]
44
+ else
45
+ if raw_input
46
+ input_enumerator = Enumerator.new do |yielder|
47
+ inputs.each do |input|
48
+ input.each_line do |line|
49
+ yielder.yield line.chop
50
+ end
51
+ end
52
+ end.lazy
53
+ else
54
+ input_enumerator = Enumerator.new do |yielder|
55
+ inputs.each do |input|
56
+ Yajl::Parser.new(symbolize_keys: true).parse(input) do |d|
57
+ yielder.yield d
58
+ end
59
+ end
60
+ end.lazy
33
61
  end
34
- end.lazy.instance_eval(ARGV[0])
62
+ end
63
+
64
+ result = input_enumerator.instance_eval(jr_filter)
35
65
 
36
66
  encoder = Yajl::Encoder.new(pretty: pretty)
37
67
  print_json = ->(data) do
@@ -2,6 +2,28 @@ Feature: JSON processing
2
2
 
3
3
  jr is jq like JSON processor for Rubyist
4
4
 
5
+ Scenario: Indent JSON
6
+ Given a file named "input.json" with:
7
+ """
8
+ {"name":"foo"}
9
+ {"name":"bar"}
10
+ {"name":"baz"}
11
+ """
12
+ When I run `cat input.json | jr` in bash
13
+ Then the output should contain exactly:
14
+ """
15
+ {
16
+ "name": "foo"
17
+ }
18
+ {
19
+ "name": "bar"
20
+ }
21
+ {
22
+ "name": "baz"
23
+ }
24
+
25
+ """
26
+
5
27
  Scenario: Filter single JSON of Object
6
28
  Given a file named "input.json" with:
7
29
  """
@@ -245,3 +267,86 @@ Feature: JSON processing
245
267
  baz
246
268
 
247
269
  """
270
+
271
+ Scenario: Read each line as string using --raw-input option
272
+ Given a file named "input.json" with:
273
+ """
274
+ foo
275
+ bar
276
+ baz
277
+
278
+ """
279
+ When I run `jr --raw-input 'self' input.json`
280
+ Then the output should contain exactly:
281
+ """
282
+ "foo"
283
+ "bar"
284
+ "baz"
285
+
286
+ """
287
+
288
+ Scenario: Read filter from file using -f option.
289
+ Given a file named "input.json" with:
290
+ """
291
+ {"ua":"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"}
292
+ {"ua":"Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3"}
293
+ {"ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:21.0) Gecko/20100101 Firefox/21.0"}
294
+
295
+ """
296
+ And a file named "filter.rb" with:
297
+ """
298
+ require 'woothee'
299
+
300
+ select { |j| not Woothee.is_crawler(j.ua) }
301
+ .map { |j| Woothee.parse(j.ua).name }
302
+ """
303
+ When I run `jr -f filter.rb input.json`
304
+ Then the output should contain exactly:
305
+ """
306
+ "Safari"
307
+ "Firefox"
308
+
309
+ """
310
+
311
+ Scenario: Read filter from file using --from-file option.
312
+ Given a file named "input.json" with:
313
+ """
314
+ {"ua":"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"}
315
+ {"ua":"Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3"}
316
+ {"ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:21.0) Gecko/20100101 Firefox/21.0"}
317
+
318
+ """
319
+ And a file named "filter.rb" with:
320
+ """
321
+ require 'woothee'
322
+
323
+ select { |j| not Woothee.is_crawler(j.ua) }
324
+ .map { |j| Woothee.parse(j.ua).name }
325
+ """
326
+ When I run `jr --from-file filter.rb input.json`
327
+ Then the output should contain exactly:
328
+ """
329
+ "Safari"
330
+ "Firefox"
331
+
332
+ """
333
+
334
+ Scenario: Read no file and build JSONs from scratch using --null-input option.
335
+ When I run `jr --null-input '1.upto(3).map{ |n| "%02d" % n }'`
336
+ Then the output should contain exactly:
337
+ """
338
+ "01"
339
+ "02"
340
+ "03"
341
+
342
+ """
343
+
344
+ Scenario: Read no file and build JSONs from scratch using -n option.
345
+ When I run `jr -n '1.upto(3).map{ |n| "%02d" % n }'`
346
+ Then the output should contain exactly:
347
+ """
348
+ "01"
349
+ "02"
350
+ "03"
351
+
352
+ """
@@ -0,0 +1,4 @@
1
+ When(/^I run `([^`]*)` in bash$/)do |cmd|
2
+ cmd = "bash -c '%s'" % unescape_text(unescape_text(cmd))
3
+ run_simple(cmd, false)
4
+ end
data/jr-cli.gemspec CHANGED
@@ -18,15 +18,15 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "yajl-ruby"
22
- spec.add_runtime_dependency "coderay"
21
+ spec.add_runtime_dependency "yajl-ruby", "~> 1.2.1"
22
+ spec.add_runtime_dependency "coderay", "~> 1.1.0"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.6"
25
- spec.add_development_dependency "rake"
26
- spec.add_development_dependency "test-unit"
27
- spec.add_development_dependency "aruba"
28
- spec.add_development_dependency "guard"
29
- spec.add_development_dependency "guard-test"
30
- spec.add_development_dependency "guard-cucumber"
31
- spec.add_development_dependency "woothee"
25
+ spec.add_development_dependency "rake", "~> 10.4.2"
26
+ spec.add_development_dependency "test-unit", "~> 3.1.3"
27
+ spec.add_development_dependency "aruba", "0.9.0"
28
+ spec.add_development_dependency "guard", "~> 2.13.0"
29
+ spec.add_development_dependency "guard-test", "~> 2.0.6"
30
+ spec.add_development_dependency "guard-cucumber", "~> 1.6.0"
31
+ spec.add_development_dependency "woothee", "~> 1.2.0"
32
32
  end
@@ -1,5 +1,5 @@
1
1
  module Jr
2
2
  module Cli
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jr-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuya Takeyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-18 00:00:00.000000000 Z
11
+ date: 2015-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yajl-ruby
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.2.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 1.2.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: coderay
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 1.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 1.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -56,100 +56,100 @@ dependencies:
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 10.4.2
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 10.4.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: test-unit
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 3.1.3
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 3.1.3
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: aruba
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 0.9.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 0.9.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: guard
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 2.13.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 2.13.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: guard-test
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: 2.0.6
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: 2.0.6
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: guard-cucumber
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '0'
131
+ version: 1.6.0
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '0'
138
+ version: 1.6.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: woothee
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '0'
145
+ version: 1.2.0
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '0'
152
+ version: 1.2.0
153
153
  description: jr is jq like JSON processor. Its script can be written in Ruby
154
154
  email:
155
155
  - sign.of.the.wolf.pentagram@gmail.com
@@ -169,6 +169,7 @@ files:
169
169
  - bin/jr
170
170
  - features/core_ext.feature
171
171
  - features/json_processing.feature
172
+ - features/step_definitions/command_steps.rb
172
173
  - features/support/env.rb
173
174
  - jr-cli.gemspec
174
175
  - lib/jr/cli/core_ext.rb
@@ -209,6 +210,7 @@ summary: 'jr: command-line JSON processor for Rubyists'
209
210
  test_files:
210
211
  - features/core_ext.feature
211
212
  - features/json_processing.feature
213
+ - features/step_definitions/command_steps.rb
212
214
  - features/support/env.rb
213
215
  - test/unit/core_ext/enumerable_test.rb
214
216
  - test/unit/core_ext/enumerator_test.rb