module Pantograph class PluginSearch require 'terminal-table' require 'word_wrap' def self.print_plugins(search_query: nil) if search_query UI.message("Looking for pantograph plugins containing '#{search_query}'...") else UI.message("Listing all available pantograph plugins") end plugins = Pantograph::PluginFetcher.fetch_gems(search_query: search_query) if plugins.empty? UI.user_error!("Couldn't find any available pantograph plugins containing '#{search_query}'") end rows = plugins.collect do |current| [ current.name.green, WordWrap.ww(current.info, 50), current.downloads ] end params = { rows: PantographCore::PrintTable.transform_output(rows), title: (search_query ? "pantograph plugins '#{search_query}'" : "Available pantograph plugins").green, headings: ["Name", "Description", "Downloads"] } puts("") puts(Terminal::Table.new(params)) puts("") if plugins.count == 1 print_plugin_details(plugins.last) end end def self.print_plugin_details(plugin) UI.message("You can find more information for #{plugin.name} on #{plugin.homepage.green}") end end end