2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-09-03 19:39:07 +01:00
|
|
|
require "cask/cask"
|
|
|
|
require "cask/cask_loader"
|
2018-06-13 07:49:01 +02:00
|
|
|
|
|
|
|
module Homebrew
|
|
|
|
module Search
|
2018-06-18 16:09:13 +02:00
|
|
|
module Extension
|
2021-07-25 20:10:35 +09:00
|
|
|
def search_descriptions(string_or_regex, args)
|
2018-06-18 16:09:13 +02:00
|
|
|
super
|
|
|
|
|
2021-07-25 20:10:35 +09:00
|
|
|
return if args.formula?
|
|
|
|
|
2022-03-23 00:03:11 -04:00
|
|
|
puts unless args.cask?
|
2018-06-18 16:09:13 +02:00
|
|
|
ohai "Casks"
|
2022-03-23 00:03:11 -04:00
|
|
|
CacheStoreDatabase.use(:cask_descriptions) do |db|
|
|
|
|
cache_store = CaskDescriptionCacheStore.new(db)
|
|
|
|
Descriptions.search(string_or_regex, :desc, cache_store).print
|
2018-06-13 07:49:01 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-18 16:09:13 +02:00
|
|
|
def search_casks(string_or_regex)
|
|
|
|
if string_or_regex.is_a?(String) && string_or_regex.match?(HOMEBREW_TAP_CASK_REGEX)
|
|
|
|
return begin
|
2018-09-06 08:29:14 +02:00
|
|
|
[Cask::CaskLoader.load(string_or_regex).token]
|
|
|
|
rescue Cask::CaskUnavailableError
|
2018-06-18 16:09:13 +02:00
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
2018-06-13 07:49:01 +02:00
|
|
|
|
2021-11-03 16:47:22 -07:00
|
|
|
cask_tokens = Tap.flat_map(&:cask_tokens)
|
2018-06-18 16:09:13 +02:00
|
|
|
|
2021-11-03 16:47:22 -07:00
|
|
|
results = cask_tokens.extend(Searchable)
|
|
|
|
.search(string_or_regex)
|
|
|
|
|
2022-03-28 21:41:40 +09:00
|
|
|
cask_names = Cask::Cask.all.map(&:full_name)
|
2022-03-28 23:57:21 +09:00
|
|
|
results += DidYouMean::SpellChecker.new(dictionary: cask_names)
|
2021-11-03 16:47:22 -07:00
|
|
|
.correct(string_or_regex)
|
|
|
|
|
|
|
|
results.sort.map do |name|
|
|
|
|
cask = Cask::CaskLoader.load(name)
|
2018-06-18 16:09:13 +02:00
|
|
|
if cask.installed?
|
2022-03-23 00:03:11 -04:00
|
|
|
pretty_installed(cask.full_name)
|
2018-06-18 16:09:13 +02:00
|
|
|
else
|
2022-03-23 00:03:11 -04:00
|
|
|
cask.full_name
|
2018-06-18 16:09:13 +02:00
|
|
|
end
|
2022-03-28 21:41:40 +09:00
|
|
|
end.uniq
|
2018-06-13 07:49:01 +02:00
|
|
|
end
|
|
|
|
end
|
2018-06-18 16:09:13 +02:00
|
|
|
|
|
|
|
prepend Extension
|
2018-06-13 07:49:01 +02:00
|
|
|
end
|
|
|
|
end
|