From 856d549b8fce48660fe2393d10d44211ffee338d Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Sun, 17 Jun 2012 09:33:40 +0200 Subject: [PATCH] Drop ypath, since there is no 1.9 implementation, implement the bits we need ourselves --- pws | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pws b/pws index 430cfa2..f0d3cd1 100755 --- a/pws +++ b/pws @@ -706,11 +706,11 @@ end class Get def help(parser, code=0, io=STDOUT) - io.puts "Usage: #{$program_name} get " + io.puts "Usage: #{$program_name} 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 "ypath is an ypath query, typically something like host/users/root" + io.puts "query is a query, formatted like host/users/root" exit(code) end @@ -722,14 +722,21 @@ class Get end begin - yaml = YAML::parse(encrypted_file.decrypt) - rescue ArgumentError => e + yaml = YAML::load(encrypted_file.decrypt) + rescue Psych::SyntaxError, ArgumentError => e STDERR.puts "Could not parse YAML: #{e.message}" exit(1) end - hit = yaml.select(what)[0].transform + + require 'pp' + + a = what.split("/") + hit = yaml + a.each do |k| + hit = hit[k] + end if hit.nil? - STDERR.puts("No such key or invalid YPath expression") + STDERR.puts("No such key or invalid lookup expression") elsif hit.respond_to?(:keys) puts "Keys:" puts hit.keys.join("\n") -- 2.39.5