Class: Chef::Knife::Search
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::Search
- Defined in:
- lib/chef/knife/search.rb
Constant Summary
Constants inherited from Chef::Knife
Instance Attribute Summary
Attributes inherited from Chef::Knife
Instance Method Summary collapse
Methods inherited from Chef::Knife
#ask_question, #bulk_delete, category, #configure_chef, #confirm, #create_object, #delete_object, #edit_data, #edit_object, #file_exists_and_is_readable?, #format_for_display, #format_list_for_display, guess_category, inherited, #initialize, list_commands, load_commands, #load_from_file, #msg, msg, #output, #parse_options, #pretty_print, #rest, run, #show_usage, snake_case_name, #stdin, #stdout, subcommand_category, subcommand_class_from, subcommands, subcommands_by_category, unnamed?
Methods included from Mixin::ConvertToClassName
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
Constructor Details
This class inherits a constructor from Chef::Knife
Instance Method Details
#run ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/chef/knife/search.rb', line 63 def run q = Chef::Search::Query.new display = { :total => 0, :start => config[:start] ? config[:start] : 0, :rows => [ ] } q.search(@name_args[0], @name_args[1], config[:sort], config[:start] ? config[:start] : 0, config[:rows] ? config[:rows] : 20) do |item| formatted_item = format_for_display(item) if formatted_item.respond_to?(:has_key?) && !formatted_item.has_key?('id') formatted_item['id'] = item.has_key?('id') ? item['id'] : item.name end display[:rows] << formatted_item display[:total] += 1 end if config[:id_only] if config[:attribute] display[:rows].each do |row| puts row[config[:attribute]] if row.has_key?(config[:attribute]) && !row[config[:attribute]].nil? end else puts display[:rows].join("\n") end else output(display) end end |