diff options
author | Seth Falcon <seth@opscode.com> | 2011-03-21 13:43:00 -0700 |
---|---|---|
committer | Seth Falcon <seth@opscode.com> | 2011-03-21 13:43:00 -0700 |
commit | 922b8f4e3a17d24b39555a9a4409440044a644c0 (patch) | |
tree | d2969a1d1f80132afc3a928378d9f8d878943613 | |
parent | af7e8636a25d01c2c7b5943d883e60bbac0380f1 (diff) | |
parent | f48f2129ea2678029eb71c944429a69952904d30 (diff) | |
download | chef-922b8f4e3a17d24b39555a9a4409440044a644c0.tar.gz |
Merge branch 'CHEF-1821'
-rw-r--r-- | chef/lib/chef/knife/search.rb | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/chef/lib/chef/knife/search.rb b/chef/lib/chef/knife/search.rb index 45bd8f51d4..c0303c4804 100644 --- a/chef/lib/chef/knife/search.rb +++ b/chef/lib/chef/knife/search.rb @@ -60,11 +60,31 @@ class Chef :long => "--id-only", :description => "Show only the ID of matching objects" + option :query, + :short => "-q QUERY", + :long => "--query QUERY", + :description => "The search query; useful to protect queries starting with -" + def run + if config[:query] && @name_args[1] + puts "please specify query as an argument or an option via -q, not both" + puts opt_parser + exit 1 + end + raw_query = config[:query] || @name_args[1] + if !raw_query || raw_query.empty? + puts "no query specified" + puts opt_parser + exit 1 + end + q = Chef::Search::Query.new display = { :total => 0, :start => config[:start] ? config[:start] : 0, :rows => [ ] } - - q.search(@name_args[0], URI.escape(@name_args[1], Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")), config[:sort], config[:start] ? config[:start] : 0, config[:rows] ? config[:rows] : 20) do |item| + query = URI.escape(raw_query, + Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) + rows = config[:rows] ? config[:rows] : 20 + start = config[:start] ? config[:start] : 0 + q.search(@name_args[0], query, config[:sort], start, rows) 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 |