mirror of
https://github.com/donl/homebrew-cask-versions.git
synced 2026-07-17 14:26:45 -06:00
* "Canonical App Name" becomes "Simplified App Name"
* devscript `cask_namer` renamed to `generate_cask_token`
* doc file `CASK_NAMING_REFERENCE.md` renamed to `cask_token_reference.md`
* DSL uses `"#{token}"` for interpolation instead of `"#{title}"`
* documentation text
* backend code (variables, method, class names)
* error message text
* tests
* code comments
* Cask comments
* emphasize `tags :name`
* doc: use "vendor" consistently instead of "developer"
* doc: many man page argument descriptions were incorrect
* incidental clarifications
Many backend variables similar to `cask_name` or `cask` have
been standardized to `cask_token`, `token`, etc, resolving a long-
standing ambiguity in which variables named `cask` might contain
a Cask instance or a string token.
In many places the docs could be shortened from "Cask name" to
simply "token", which is desirable because we use the term "Cask"
in too many contexts.
56 lines
1.8 KiB
Ruby
56 lines
1.8 KiB
Ruby
class Cask::CLI::Search < Cask::CLI::Base
|
|
def self.run(*arguments)
|
|
render_results *search(*arguments)
|
|
end
|
|
|
|
def self.extract_regexp(string)
|
|
if %r{^/(.*)/$}.match(string) then
|
|
$1
|
|
else
|
|
false
|
|
end
|
|
end
|
|
|
|
def self.search(*arguments)
|
|
exact_match = nil
|
|
partial_matches = []
|
|
search_term = arguments.join(' ')
|
|
search_regexp = extract_regexp arguments.first
|
|
if search_regexp
|
|
search_term = arguments.first
|
|
partial_matches = Cask::CLI.nice_listing(Cask.all_tokens).grep(/#{search_regexp}/i)
|
|
else
|
|
# suppressing search of the font Tap is a quick hack until behavior can be made configurable
|
|
all_tokens = Cask::CLI.nice_listing Cask.all_tokens.reject{ |t| %r{^caskroom/homebrew-fonts/}.match(t)}
|
|
simplified_tokens = all_tokens.map { |t| t.sub(/^.*\//, '').gsub(/[^a-z0-9]+/i, '') }
|
|
simplified_search_term = search_term.sub(/\.rb$/i, '').gsub(/[^a-z0-9]+/i, '')
|
|
exact_match = simplified_tokens.grep(/^#{simplified_search_term}$/i) { |t| all_tokens[simplified_tokens.index(t)] }.first
|
|
partial_matches = simplified_tokens.grep(/#{simplified_search_term}/i) { |t| all_tokens[simplified_tokens.index(t)] }
|
|
partial_matches.delete(exact_match)
|
|
end
|
|
return exact_match, partial_matches, search_term
|
|
end
|
|
|
|
def self.render_results(exact_match, partial_matches, search_term)
|
|
if ! exact_match and partial_matches.empty?
|
|
puts "No Cask found for \"#{search_term}\"."
|
|
return
|
|
end
|
|
if exact_match
|
|
ohai "Exact match"
|
|
puts exact_match
|
|
end
|
|
unless partial_matches.empty?
|
|
if extract_regexp search_term
|
|
ohai "Regexp matches"
|
|
else
|
|
ohai "Partial matches"
|
|
end
|
|
puts_columns partial_matches
|
|
end
|
|
end
|
|
|
|
def self.help
|
|
"searches all known Casks"
|
|
end
|
|
end
|