require "cbor" if ARGV.size >= 1 && ARGV[0] == "-h" puts "usage: cq < file.cbor" puts "usage: cq [attribute] < file" 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 if v = data[attribute]? return v end else STDERR.puts "attribute not found: #{attribute}" return nil end 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