lib/plugins/puppet-debugger/input_responders/resources.rb in puppet-debugger-0.17.0 vs lib/plugins/puppet-debugger/input_responders/resources.rb in puppet-debugger-0.18.0

- old
+ new

@@ -5,17 +5,23 @@ COMMAND_WORDS = %w(resources) SUMMARY = 'List all the resources current in the catalog.' COMMAND_GROUP = :scope def run(args = []) - res = debugger.scope.compiler.catalog.resources.map do |res| + filter = args + resources = find_resources(debugger.catalog.resources, filter) + modified = resources.map do |res| res.to_s.gsub(/\[/, "['").gsub(/\]/, "']") # ensure the title has quotes end - if !args.first.nil? - res[args.first.to_i].ai - else - output = "Resources not shown in any specific order\n".warning - output += res.ai + output = "Resources not shown in any specific order\n".warning + output += modified.ai + end + + def find_resources(resources, filter = []) + return resources if filter.nil? || filter.empty? + filter_string = filter.join(' ').downcase + resources.find_all do |resource| + resource.name.to_s.downcase.include?(filter_string) || resource.type.to_s.downcase.include?(filter_string) end end end end end