Class: Chef::Knife::CookbookShow

Inherits:
Chef::Knife show all
Defined in:
lib/chef/knife/cookbook_show.rb

Instance Attribute Summary

Attributes inherited from Chef::Knife

#name_args

Instance Method Summary collapse

Methods inherited from Chef::Knife

#ask_question, build_sub_class, #bulk_delete, #configure_chef, #confirm, #create_object, #delete_object, #edit_data, #edit_object, #file_exists_and_is_readable?, find_command, #format_for_display, #format_list_for_display, #json_pretty_print, list_commands, load_commands, #load_from_file, #pretty_print, #rest

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string

Instance Method Details

#make_query_params(req_opts) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/chef/knife/cookbook_show.rb', line 61

def make_query_params(req_opts)
  query_part = Array.new 
  req_opts.keys.sort { |a,b| a.to_s <=> b.to_s }.each do |key|
    query_part << "#{key}=#{URI.escape(req_opts[key])}"
  end
  query_part.join("&")
end

#runObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/chef/knife/cookbook_show.rb', line 44

def run 
  case @name_args.length
  when 3 # We are showing a specific file
    arguments = { :id => @name_args[2] } 
    arguments[:fqdn] = config[:fqdn] if config.has_key?(:fqdn)
    arguments[:platform] = config[:platform] if config.has_key?(:platform)
    arguments[:version] = config[:platform_version] if config.has_key?(:platform_version)
    result = rest.get_rest("cookbooks/#{@name_args[0]}/#{@name_args[1]}?#{make_query_params(arguments)}")
    pretty_print(result)
  when 2 # We are showing a specific part of the cookbook
    result = rest.get_rest("cookbooks/#{@name_args[0]}")
    json_pretty_print(result[@name_args[1]])
  when 1 # We are showing the whole cookbook data
    json_pretty_print(rest.get_rest("cookbooks/#{@name_args[0]}"))
  end
end