Skip to content

Commit 2846f4d

Browse files
sdelanoNuo Yan
authored andcommitted
knife cookbook list respects environments
1 parent bfdb457 commit 2846f4d

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

‎chef/lib/chef/knife/cookbook_list.rb‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,19 @@ class CookbookList < Knife
3030
:long => "--with-uri",
3131
:description => "Show corresponding URIs"
3232

33-
def run
34-
output(format_list_for_display(rest.get_rest('cookbooks')))
33+
def run
34+
env = config[:environment]
35+
api_endpoint = env ? "/environments/#{env}/cookbooks" : "/cookbooks/_latest"
36+
output(format_cookbooks_for_display(rest.get_rest(api_endpoint)))
37+
end
38+
39+
def format_cookbooks_for_display(api_result)
40+
api_result.map do |name, uri|
41+
version = uri.split("/").last
42+
result = [name, version]
43+
result << uri if config[:with_uri]
44+
result
45+
end
3546
end
3647
end
3748
end

0 commit comments

Comments
 (0)