From a86e35591fe666d1d22d517dbd83e5fe91619657 Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Sat, 15 Jun 2013 00:51:57 +0200 Subject: [PATCH] Fix up formatting of queries, list keys --- pws | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pws b/pws index f0d3cd1..1d222cb 100755 --- a/pws +++ b/pws @@ -710,7 +710,7 @@ class Get io.puts parser.summarize io.puts "Decrypts the file, fetches a key and outputs it to stdout." io.puts "The file must be in YAML format." - io.puts "query is a query, formatted like host/users/root" + io.puts "query is a query, formatted like /host/users/root" exit(code) end @@ -730,8 +730,16 @@ class Get require 'pp' - a = what.split("/") + a = what.split("/")[1..-1] hit = yaml + if a.nil? + # q = /, so print top level keys + puts "Keys:" + hit.keys.each do |k| + puts "- #{k}" + end + return + end a.each do |k| hit = hit[k] end @@ -739,7 +747,9 @@ class Get STDERR.puts("No such key or invalid lookup expression") elsif hit.respond_to?(:keys) puts "Keys:" - puts hit.keys.join("\n") + hit.keys.each do |k| + puts "- #{k}" + end else puts hit end -- 2.39.5