From 0d5c1ba1518820e4c4dc9eb732b422e94b4b5c24 Mon Sep 17 00:00:00 2001 From: Steven Danna Date: Thu, 22 Jan 2015 15:55:37 +0000 Subject: Add Knife::Core::UI#edit_hash edit_hash is similar to edit_data except that it returns an uninflated hash. edit_data returns either a string/IO, a hash, or a full ruby object, making it difficult to work with. --- lib/chef/knife.rb | 1 + lib/chef/knife/core/ui.rb | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/chef') diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb index 10774acc46..e13f80b5a8 100644 --- a/lib/chef/knife.rb +++ b/lib/chef/knife.rb @@ -53,6 +53,7 @@ class Chef def_delegator :@ui, :format_for_display def_delegator :@ui, :format_cookbook_list_for_display def_delegator :@ui, :edit_data + def_delegator :@ui, :edit_hash def_delegator :@ui, :edit_object def_delegator :@ui, :confirm diff --git a/lib/chef/knife/core/ui.rb b/lib/chef/knife/core/ui.rb index 00a4834638..a54f14afc1 100644 --- a/lib/chef/knife/core/ui.rb +++ b/lib/chef/knife/core/ui.rb @@ -163,9 +163,17 @@ class Chef end end + + # Hash -> Hash + # Works the same as edit_data but + # returns a hash rather than a JSON string/Fully infated object + def edit_hash(hash) + raw = edit_data(hash, false) + Chef::JSONCompat.parse(raw) + end + def edit_data(data, parse_output=true) output = Chef::JSONCompat.to_json_pretty(data) - if (!config[:disable_editing]) Tempfile.open([ 'knife-edit-', '.json' ]) do |tf| tf.sync = true -- cgit v1.2.1