cq: loop over STDIN, seems working.

master
Karchnu 2020-11-29 01:08:18 +01:00
parent 0408d94fdc
commit c094ed7dfb
1 changed files with 20 additions and 12 deletions

View File

@ -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|
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
buffer = Bytes.new 1_000_000 # 1 MB
end