54 lines
1.3 KiB
Ruby
Raw Normal View History

require "search"
2016-09-24 13:52:43 +02:00
module Hbc
class CLI
2017-05-20 19:08:03 +02:00
class Search < AbstractCommand
extend Homebrew::Search
2017-05-20 03:44:21 +02:00
def run
if args.empty?
2018-04-14 11:32:29 +02:00
puts Formatter.columns(CLI.nice_listing(Cask.map(&:qualified_token)))
else
results = self.class.search(*args)
self.class.render_results(*results)
end
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def self.search(*arguments)
2018-06-07 14:42:58 +02:00
query = arguments.join(" ")
string_or_regex = query_regexp(query)
local_results = search_casks(string_or_regex)
2018-06-07 14:42:58 +02:00
remote_matches = search_taps(query, silent: true)[:casks]
2018-06-07 14:42:58 +02:00
[local_results, remote_matches, query]
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
def self.render_results(partial_matches, remote_matches, search_term)
unless $stdout.tty?
puts [*partial_matches, *remote_matches]
return
end
if partial_matches.empty? && remote_matches.empty?
2016-09-24 13:52:43 +02:00
puts "No Cask found for \"#{search_term}\"."
return
end
2016-10-24 17:07:57 +02:00
unless partial_matches.empty?
2018-06-07 14:42:58 +02:00
ohai "Matches"
puts Formatter.columns(partial_matches)
2016-09-24 13:52:43 +02:00
end
return if remote_matches.empty?
ohai "Remote Matches"
2018-06-07 14:42:58 +02:00
puts Formatter.columns(remote_matches)
end
2016-09-24 13:52:43 +02:00
def self.help
"searches all known Casks"
end
end
2016-08-18 22:11:42 +03:00
end
end