2018-06-02 20:49:14 +02:00
|
|
|
require "search"
|
2018-06-02 02:25:20 +02:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
module Hbc
|
|
|
|
class CLI
|
2017-05-20 19:08:03 +02:00
|
|
|
class Search < AbstractCommand
|
2018-06-02 20:49:14 +02:00
|
|
|
extend Homebrew::Search
|
|
|
|
|
2017-05-20 03:44:21 +02:00
|
|
|
def run
|
2017-08-23 03:23:33 +02:00
|
|
|
if args.empty?
|
2018-04-14 11:32:29 +02:00
|
|
|
puts Formatter.columns(CLI.nice_listing(Cask.map(&:qualified_token)))
|
2017-08-23 03:23:33 +02:00
|
|
|
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)
|
2017-04-24 19:31:36 +02:00
|
|
|
|
2018-06-07 14:42:58 +02:00
|
|
|
remote_matches = search_taps(query, silent: true)[:casks]
|
2017-04-24 19:31:36 +02:00
|
|
|
|
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
|
|
|
|
2018-06-02 02:47:23 +02:00
|
|
|
def self.render_results(partial_matches, remote_matches, search_term)
|
2017-07-06 01:08:59 +02:00
|
|
|
unless $stdout.tty?
|
2018-06-02 02:47:23 +02:00
|
|
|
puts [*partial_matches, *remote_matches]
|
2017-07-06 01:08:59 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-06-02 02:47:23 +02:00
|
|
|
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
|
|
|
|
2017-04-24 19:31:36 +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
|
2017-04-24 19:31:36 +02:00
|
|
|
|
|
|
|
return if remote_matches.empty?
|
|
|
|
ohai "Remote Matches"
|
2018-06-07 14:42:58 +02:00
|
|
|
puts Formatter.columns(remote_matches)
|
2017-03-11 16:25:02 -08:00
|
|
|
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
|