cq: loop over STDIN, seems working.
This commit is contained in:
parent
0408d94fdc
commit
c094ed7dfb
32
src/cq.cr
32
src/cq.cr
@ -6,13 +6,6 @@ if ARGV.size >= 1 && ARGV[0] == "-h"
|
||||
exit 0
|
||||
end
|
||||
|
||||
data = CBOR::Decoder.new(STDIN).read_value
|
||||
|
||||
if ARGV.size == 0
|
||||
pp data
|
||||
exit 0
|
||||
end
|
||||
|
||||
def dig(data, attribute : String)
|
||||
case data
|
||||
when Hash
|
||||
@ -25,10 +18,25 @@ def dig(data, attribute : String)
|
||||
end
|
||||
end
|
||||
|
||||
ARGV.each do |attribute|
|
||||
current_data = data.clone
|
||||
attribute.split(/[.]/).each do |attr|
|
||||
current_data = dig current_data, attr
|
||||
buffer = Bytes.new 1_000_000 # 1 MB
|
||||
|
||||
until STDIN.read(buffer) == 0
|
||||
decoder = CBOR::Decoder.new(buffer)
|
||||
while data = decoder.read_value
|
||||
break if data == 0
|
||||
|
||||
if ARGV.size == 0
|
||||
pp data
|
||||
next
|
||||
end
|
||||
|
||||
ARGV.each do |attribute|
|
||||
current_data = data.clone
|
||||
attribute.split(/[.]/).each do |attr|
|
||||
current_data = dig current_data, attr
|
||||
end
|
||||
pp current_data
|
||||
end
|
||||
end
|
||||
pp current_data
|
||||
buffer = Bytes.new 1_000_000 # 1 MB
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user