jr-cli 0.3.1 → 0.4.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -0
- data/bin/jr +8 -1
- data/lib/jr/cli/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3eb780e24677fc860ad761bc334ecb29eb45e09f
|
|
4
|
+
data.tar.gz: 695c705288ff8bd671a6bce707a5a96cc0ebacf0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 61004562f569c2fcf351279c14d37bf4e286d66fff7d34277d019d5914173ba4d8a502906b1c785ce66cfb9e49fad623f048498e5d6f608c272d92a0935b7cff
|
|
7
|
+
data.tar.gz: 3584d348cef55a566aca3622b7639523436b521afc81e2ff3d0666cebc120a67752fa724ec5201de2e36e676b380d505a22f6ceae9638958bcccf4e5ea5de77a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -40,6 +40,7 @@ You can also read JSON not from files but from STDIN.
|
|
|
40
40
|
-C, --color-output output with colors even if writing to a pipe or a file
|
|
41
41
|
-M, --monochrome-output output without colors
|
|
42
42
|
-n, --null-input use null as input instead of any files
|
|
43
|
+
--unbuffered output each JSON without buffering
|
|
43
44
|
```
|
|
44
45
|
|
|
45
46
|
## jr filter tutorial
|
data/bin/jr
CHANGED
|
@@ -6,6 +6,9 @@ require 'optparse'
|
|
|
6
6
|
require 'yajl'
|
|
7
7
|
require 'coderay'
|
|
8
8
|
|
|
9
|
+
DEFAULT_BUFFER_SIZE = 8192
|
|
10
|
+
UNBUFFERED_BUFFER_SIZE = 1
|
|
11
|
+
|
|
9
12
|
opt = OptionParser.new
|
|
10
13
|
opt.banner = "jr - Command-line JSON processor for Rubyists [Ver. #{Jr::Cli::VERSION}]\n\n" +
|
|
11
14
|
"Usage: jr [options] <jr filter> [file...]"
|
|
@@ -25,6 +28,9 @@ opt.on('-C', '--color-output', 'output with colors even if writing to a pip
|
|
|
25
28
|
opt.on('-M', '--monochrome-output', 'output without colors') { color_output = false }
|
|
26
29
|
null_input = false
|
|
27
30
|
opt.on('-n', '--null-input', 'use null as input instead of any files') { null_input = true }
|
|
31
|
+
unbuffered = false
|
|
32
|
+
buffer_size = DEFAULT_BUFFER_SIZE
|
|
33
|
+
opt.on('--unbuffered', 'output each JSON without buffering') { unbuffered = true; buffer_size = UNBUFFERED_BUFFER_SIZE }
|
|
28
34
|
opt.parse! ARGV
|
|
29
35
|
|
|
30
36
|
require 'jr/cli/core_ext'
|
|
@@ -53,7 +59,7 @@ else
|
|
|
53
59
|
else
|
|
54
60
|
input_enumerator = Enumerator.new do |yielder|
|
|
55
61
|
inputs.each do |input|
|
|
56
|
-
Yajl::Parser.new(symbolize_keys: true).parse(input) do |d|
|
|
62
|
+
Yajl::Parser.new(symbolize_keys: true).parse(input, buffer_size) do |d|
|
|
57
63
|
yielder.yield d
|
|
58
64
|
end
|
|
59
65
|
end
|
|
@@ -79,6 +85,7 @@ end
|
|
|
79
85
|
if result.is_a? Enumerable and !result.is_a? Hash
|
|
80
86
|
result.each do |data|
|
|
81
87
|
print_json.call data
|
|
88
|
+
STDOUT.flush if unbuffered
|
|
82
89
|
end
|
|
83
90
|
else
|
|
84
91
|
print_json.call result
|
data/lib/jr/cli/version.rb
CHANGED