lib/chef/knife/Decrypt.rb in chef-vault-2.0.2 vs lib/chef/knife/Decrypt.rb in chef-vault-2.1.0

- old
+ new

@@ -23,23 +23,23 @@ require File.expand_path('../mixin/helper', __FILE__) include ChefVault::Mixin::KnifeCompat include ChefVault::Mixin::Helper end - banner "knife decrypt [VAULT] [ITEM] [VALUES] --mode MODE" + banner "knife decrypt VAULT ITEM [VALUES] --mode MODE" option :mode, :short => '-M MODE', :long => '--mode MODE', - :description => 'Chef mode to run in default - solo' + :description => 'Chef mode to run in default - solo' def run vault = @name_args[0] item = @name_args[1] values = @name_args[2] - if vault && item && values + if vault && item set_mode(config[:mode]) print_values(vault, item, values) else show_usage @@ -50,15 +50,22 @@ super exit 1 end def print_values(vault, item, values) - vault_item = ChefVault::Item.load(vault, item) + vault_item = ChefVault::Item.load(vault, item).raw_data - puts "#{vault}/#{item}" + if values + included_values = %W( id ) - values.split(",").each do |value| - value.strip! # remove white space - puts("\t#{value}: #{vault_item[value]}") + values.split(",").each do |value| + value.strip! # remove white space + included_values << value + end + + output(Hash[vault_item.find_all{|k,v| included_values.include?(k)}]) + else + output(vault_item) end - end + end end +