56 lines
1.3 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: false
# frozen_string_literal: true
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
def search_descriptions(string_or_regex, args)
2018-06-18 16:09:13 +02:00
super
puts
return if args.formula?
2018-06-18 16:09:13 +02:00
ohai "Casks"
Cask::Cask.all.extend(Searchable)
2018-09-06 08:29:14 +02:00
.search(string_or_regex, &:name)
.each do |cask|
2018-06-18 16:09:13 +02:00
puts "#{Tty.bold}#{cask.token}:#{Tty.reset} #{cask.name.join(", ")}"
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)
results |= DidYouMean::SpellChecker.new(dictionary: cask_tokens)
.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?
pretty_installed(cask.token)
else
cask.token
end
2018-06-13 07:49:01 +02:00
end
end
end
2018-06-18 16:09:13 +02:00
prepend Extension
2018-06-13 07:49:01 +02:00
end
end