summaryrefslogtreecommitdiff
path: root/lib/chef/knife/cookbook_show.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/knife/cookbook_show.rb')
-rw-r--r--lib/chef/knife/cookbook_show.rb16
1 files changed, 6 insertions, 10 deletions
diff --git a/lib/chef/knife/cookbook_show.rb b/lib/chef/knife/cookbook_show.rb
index 5fab7c303f..a20e62ffc2 100644
--- a/lib/chef/knife/cookbook_show.rb
+++ b/lib/chef/knife/cookbook_show.rb
@@ -51,6 +51,10 @@ class Chef
:description => "Show corresponding URIs"
def run
+ cookbook_name, cookbook_version, segment, filename = @name_args
+
+ cookbook = Chef::CookbookVersion.load(cookbook_name, cookbook_version) unless cookbook_version.nil?
+
case @name_args.length
when 4 # We are showing a specific file
node = Hash.new
@@ -64,10 +68,6 @@ class Chef
end
end
- cookbook_name, segment, filename = @name_args[0], @name_args[2], @name_args[3]
- cookbook_version = @name_args[1] == "latest" ? "_latest" : @name_args[1]
-
- cookbook = rest.get("cookbooks/#{cookbook_name}/#{cookbook_version}")
manifest_entry = cookbook.preferred_manifest_record(node, segment, filename)
temp_file = rest.streaming_request(manifest_entry[:url])
@@ -76,14 +76,10 @@ class Chef
pretty_print(temp_file.read)
when 3 # We are showing a specific part of the cookbook
- cookbook_version = @name_args[1] == "latest" ? "_latest" : @name_args[1]
- result = rest.get("cookbooks/#{@name_args[0]}/#{cookbook_version}")
- output(result.manifest[@name_args[2]])
+ output(cookbook.manifest[segment])
when 2 # We are showing the whole cookbook data
- cookbook_version = @name_args[1] == "latest" ? "_latest" : @name_args[1]
- output(rest.get("cookbooks/#{@name_args[0]}/#{cookbook_version}"))
+ output(cookbook)
when 1 # We are showing the cookbook versions (all of them)
- cookbook_name = @name_args[0]
env = config[:environment]
api_endpoint = env ? "environments/#{env}/cookbooks/#{cookbook_name}" : "cookbooks/#{cookbook_name}"
output(format_cookbook_list_for_display(rest.get(api_endpoint)))