lib/chef/knife/cookbook_show.rb in chef-0.9.18 vs lib/chef/knife/cookbook_show.rb in chef-0.10.0.beta.0
- old
+ new
@@ -15,17 +15,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'chef/knife'
-require 'chef/json_compat'
-require 'uri'
class Chef
class Knife
class CookbookShow < Knife
+ deps do
+ require 'chef/json_compat'
+ require 'uri'
+ end
+
banner "knife cookbook show COOKBOOK [VERSION] [PART] [FILENAME] (options)"
option :fqdn,
:short => "-f FQDN",
:long => "--fqdn FQDN",
@@ -39,10 +42,15 @@
option :platform_version,
:short => "-V VERSION",
:long => "--platform-version VERSION",
:description => "The platform version to see the file for"
+ option :with_uri,
+ :short => "-w",
+ :long => "--with-uri",
+ :description => "Show corresponding URIs"
+
def run
case @name_args.length
when 4 # We are showing a specific file
node = Hash.new
node[:fqdn] = config[:fqdn] if config.has_key?(:fqdn)
@@ -71,14 +79,17 @@
result = rest.get_rest("cookbooks/#{@name_args[0]}/#{cookbook_version}")
output(result.manifest[@name_args[2]])
when 2 # We are showing the whole cookbook data
cookbook_version = @name_args[1] == 'latest' ? '_latest' : @name_args[1]
output(rest.get_rest("cookbooks/#{@name_args[0]}/#{cookbook_version}"))
- when 1 # We are showing the cookbook versions
- output(rest.get_rest("cookbooks/#{@name_args[0]}"))
+ 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_rest(api_endpoint)))
when 0
show_usage
- Chef::Log.fatal("You must specify a cookbook name")
+ ui.fatal("You must specify a cookbook name")
exit 1
end
end
end
end