diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb index df3271a5d9..d88e365ab2 100644 --- a/Library/Homebrew/cask/lib/hbc/cli.rb +++ b/Library/Homebrew/cask/lib/hbc/cli.rb @@ -21,7 +21,6 @@ require "hbc/cli/install" require "hbc/cli/list" require "hbc/cli/outdated" require "hbc/cli/reinstall" -require "hbc/cli/search" require "hbc/cli/style" require "hbc/cli/uninstall" require "hbc/cli/upgrade" diff --git a/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb b/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb index e6313b5fc5..59268715fa 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb @@ -1,9 +1,11 @@ require_relative "options" +require "search" module Hbc class CLI class AbstractCommand include Options + include Homebrew::Search option "--[no-]binaries", :binaries, true option "--debug", :debug, false @@ -50,7 +52,7 @@ module Hbc end def suggestion_message(cask_token) - matches, = Search.search(cask_token) + matches = search_casks(cask_token) if matches.one? "Did you mean “#{matches.first}”?" diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb deleted file mode 100644 index d7bd079bd1..0000000000 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ /dev/null @@ -1,53 +0,0 @@ -require "search" - -module Hbc - class CLI - class Search < AbstractCommand - extend Homebrew::Search - - def run - if args.empty? - puts Formatter.columns(CLI.nice_listing(Cask.map(&:qualified_token))) - else - results = self.class.search(*args) - self.class.render_results(*results) - end - end - - def self.search(*arguments) - query = arguments.join(" ") - string_or_regex = query_regexp(query) - local_results = search_casks(string_or_regex) - - remote_matches = search_taps(query, silent: true)[:casks] - - [local_results, remote_matches, query] - end - - 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? - puts "No Cask found for \"#{search_term}\"." - return - end - - unless partial_matches.empty? - ohai "Matches" - puts Formatter.columns(partial_matches) - end - - return if remote_matches.empty? - ohai "Remote Matches" - puts Formatter.columns(remote_matches) - end - - def self.help - "searches all known Casks" - end - end - end -end diff --git a/Library/Homebrew/compat/hbc.rb b/Library/Homebrew/compat/hbc.rb index b64c3e4377..e41f39f856 100644 --- a/Library/Homebrew/compat/hbc.rb +++ b/Library/Homebrew/compat/hbc.rb @@ -1,4 +1,5 @@ require "compat/hbc/cask_loader" +require "compat/hbc/cli/search" require "compat/hbc/cli/update" require "compat/hbc/cache" require "compat/hbc/caskroom" diff --git a/Library/Homebrew/compat/hbc/cli.rb b/Library/Homebrew/compat/hbc/cli.rb index fb17a1d050..b80fd409d0 100644 --- a/Library/Homebrew/compat/hbc/cli.rb +++ b/Library/Homebrew/compat/hbc/cli.rb @@ -1,4 +1,4 @@ -require "cask/lib/hbc/cli/options" +require "hbc/cli/options" module Hbc class CLI diff --git a/Library/Homebrew/compat/hbc/cli/search.rb b/Library/Homebrew/compat/hbc/cli/search.rb new file mode 100644 index 0000000000..9d9f3d52fe --- /dev/null +++ b/Library/Homebrew/compat/hbc/cli/search.rb @@ -0,0 +1,21 @@ +require "hbc/cli/abstract_command" +require "cmd/search" + +module Hbc + class CLI + module Compat + class Search < AbstractCommand + def run + odeprecated "`brew cask search`", "`brew search`" + Homebrew.search(args) + end + + def self.visible + false + end + end + end + + prepend Compat + end +end diff --git a/Library/Homebrew/compat/hbc/cli/update.rb b/Library/Homebrew/compat/hbc/cli/update.rb index 348e3a2c76..5f0f255d86 100644 --- a/Library/Homebrew/compat/hbc/cli/update.rb +++ b/Library/Homebrew/compat/hbc/cli/update.rb @@ -1,10 +1,10 @@ -require "cask/lib/hbc/cli/abstract_command" +require "hbc/cli/abstract_command" module Hbc class CLI module Compat class Update < AbstractCommand - def self.run(*_ignored) + def run odisabled "`brew cask update`", "`brew update`" end diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index fb4b764d98..7421fb5c73 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -16,6 +16,7 @@ require "time" def require?(path) return false if path.nil? require path + true rescue LoadError => e # we should raise on syntax errors but not if the file doesn't exist. raise unless e.message.include?(path)