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, list_commands, load_commands, #load_from_file, #output, #pretty_print, #rest, #stdin, #stdout

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename

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]}")
    output(result[@name_args[1]])
  when 1 # We are showing the whole cookbook data
    output(rest.get_rest("cookbooks/#{@name_args[0]}"))
  end
end