diff options
author | Steven Danna <steve@opscode.com> | 2015-01-22 15:55:37 +0000 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2015-02-09 21:19:44 -0500 |
commit | 0d5c1ba1518820e4c4dc9eb732b422e94b4b5c24 (patch) | |
tree | bac4992862aebda62367b1b168eadb21da120ebf | |
parent | 8ffa43844287691e2b88287cab6033b35b723b40 (diff) | |
download | chef-0d5c1ba1518820e4c4dc9eb732b422e94b4b5c24.tar.gz |
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.
-rw-r--r-- | lib/chef/knife.rb | 1 | ||||
-rw-r--r-- | lib/chef/knife/core/ui.rb | 10 |
2 files changed, 10 insertions, 1 deletions
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 |