diff options
author | Scott Hain <shain@getchef.com> | 2014-07-29 08:39:02 -0700 |
---|---|---|
committer | Claire McQuin <claire@getchef.com> | 2014-09-04 15:52:24 -0700 |
commit | f294010caf2369da57a9950718962ee92126f478 (patch) | |
tree | 4a9657b0fcc071e6d77d823c2dce985f0fc023e5 | |
parent | 97da8b5a8c5f86151b07c85ecfd7e52c1516c058 (diff) | |
download | chef-f294010caf2369da57a9950718962ee92126f478.tar.gz |
Modified -a ATTR search to use search filtering natively. Feels sort of hack-y
-rw-r--r-- | lib/chef/knife/search.rb | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/lib/chef/knife/search.rb b/lib/chef/knife/search.rb index a382f34b6c..3eec1bd02c 100644 --- a/lib/chef/knife/search.rb +++ b/lib/chef/knife/search.rb @@ -74,7 +74,7 @@ class Chef option :filter_result, :short => "-f FILTER", :long => "--filter-result FILTER", - :description => "Only bring back specific attributes of the matching objects" + :description => "Only bring back specific attributes of the matching objects; for example: \"ServerName=name, Kernel=kernel.version\"" def run read_cli_args @@ -84,7 +84,6 @@ class Chef ui.use_presenter Knife::Core::NodePresenter end - q = Chef::Search::Query.new escaped_query = URI.escape(@query, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) @@ -98,15 +97,18 @@ class Chef search_args[:rows] = config[:rows] if config[:filter_result] search_args[:filter_result] = create_result_filter(config[:filter_result]) + elsif (not ui.config[:attribute].nil?) && (not ui.config[:attribute].empty?) + search_args[:filter_result] = create_result_filter_from_attributes(ui.config[:attribute]) end begin - # TODO - fix formatting for filtered results q.search(@type, escaped_query, search_args) 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 + formatted_item = Hash.new + if item.is_a?(Hash) + formatted_item[item["url"]] = item["data"] + else + formatted_item = format_for_display(item) + end result_items << formatted_item result_count += 1 end @@ -130,6 +132,10 @@ class Chef end end + def munge_return_data(item) + + end + def read_cli_args if config[:query] if @name_args[1] @@ -183,10 +189,14 @@ class Chef return final_filter end + def create_result_filter_from_attributes(filter_array) + final_filter = Hash.new + filter_array.each do |f| + final_filter[f.to_sym] = f.split(".") + end + return final_filter + end + end end end - - - - |