class KnifeCount::Count
This has to be a sub-module because the name is used by knife to compute the command name.
Public Instance Methods
run()
click to toggle source
# File lib/chef/knife/count.rb, line 31 def run parse_cli_args fuzzify_query run_search end
Private Instance Methods
fuzzify_query()
click to toggle source
From chef/knife/search.rb. Copyright 2009-2016, Chef Software Inc. Used under the terms of the Apache 2.0 License.
# File lib/chef/knife/count.rb, line 56 def fuzzify_query if @query !~ /:/ @query = "tags:*#{@query}* OR roles:*#{@query}* OR fqdn:*#{@query}* OR addresses:*#{@query}* OR policy_name:*#{@query}* OR policy_group:*#{@query}*" end end
parse_cli_args()
click to toggle source
# File lib/chef/knife/count.rb, line 39 def parse_cli_args case name_args.length when 0 @type = 'node' @query = '*:*' when 1 @type = 'node' @query = name_args.first else @type = name_args[0] @query = name_args[1..-1].join(' ') end end
run_search()
click to toggle source
# File lib/chef/knife/count.rb, line 62 def run_search escaped_query = Addressable::URI.encode_component(@query, Addressable::URI::CharacterClasses::QUERY) response = rest.post("/search/#{@type}?q=#{escaped_query}&rows=1", {}) ui.msg(response['total']) end