Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
Allow searching/installing Homebrew Casks.
Browse files Browse the repository at this point in the history
People want to install things like GIMP using Homebrew so let's make it
easier for them to find a decent installation method.

Closes #34496.

Signed-off-by: Mike McQuaid <[email protected]>
  • Loading branch information
MikeMcQuaid committed Nov 30, 2014
1 parent 05fa099 commit 6651fb8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
14 changes: 13 additions & 1 deletion Library/Homebrew/cmd/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,26 @@ def install
msg = blacklisted? name
raise "No available formula for #{name}\n#{msg}" if msg
end
if not File.exist? name and name =~ HOMEBREW_TAP_FORMULA_REGEX then
if !File.exist?(name) && (name =~ HOMEBREW_TAP_FORMULA_REGEX \
|| name =~ HOMEBREW_CASK_TAP_FORMULA_REGEX)
install_tap $1, $2
end
end unless ARGV.force?

begin
formulae = []

if ARGV.casks.any?
brew_cask = Formulary.factory("brew-cask")
install_formula(brew_cask) unless brew_cask.installed?

ARGV.casks.each do |c|
cmd = "brew", "cask", "install", c
ohai cmd.join " "
system *cmd
end
end

ARGV.formulae.each do |f|
# Building head-only without --HEAD is an error
if not ARGV.build_head? and f.stable.nil?
Expand Down
8 changes: 6 additions & 2 deletions Library/Homebrew/cmd/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def search
%w{Homebrew binary},
%w{Homebrew python},
%w{Homebrew php},
%w{Caskroom cask},
]

def query_regexp(query)
Expand All @@ -94,7 +95,10 @@ def search_taps(rx)
end

def search_tap user, repo, rx
return [] if (HOMEBREW_LIBRARY/"Taps/#{user.downcase}/homebrew-#{repo.downcase}").directory?
if (HOMEBREW_LIBRARY/"Taps/#{user.downcase}/homebrew-#{repo.downcase}").directory? && \
"#{user}/#{repo}" != "Caskroom/cask"
return []
end

results = []
tree = {}
Expand All @@ -113,7 +117,7 @@ def search_tap user, repo, rx
end
end

paths = tree["Formula"] || tree["HomebrewFormula"] || tree["."] || []
paths = tree["Formula"] || tree["HomebrewFormula"] || tree["Casks"] || tree["."] || []
paths.each do |path|
name = File.basename(path, ".rb")
results << "#{user}/#{repo}/#{name}" if rx === name
Expand Down
6 changes: 5 additions & 1 deletion Library/Homebrew/extend/ARGV.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ def flags_only

def formulae
require "formula"
@formulae ||= downcased_unique_named.map { |name| Formulary.factory(name, spec) }
@formulae ||= (downcased_unique_named - casks).map { |name| Formulary.factory(name, spec) }
end

def casks
@casks ||= downcased_unique_named.grep HOMEBREW_CASK_TAP_FORMULA_REGEX
end

def kegs
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/tap_constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
HOMEBREW_TAP_DIR_REGEX = %r{#{Regexp.escape(HOMEBREW_LIBRARY.to_s)}/Taps/([\w-]+)/([\w-]+)}
# match taps' formula path, e.g. HOMEBREW_LIBRARY/Taps/someuser/sometap/someformula
HOMEBREW_TAP_PATH_REGEX = Regexp.new(HOMEBREW_TAP_DIR_REGEX.source + %r{/(.*)}.source)
# match the default brew-cask tap e.g. Caskroom/cask
HOMEBREW_CASK_TAP_FORMULA_REGEX = %r{^(Caskroom)/(cask)/([\w+-.]+)$}
5 changes: 5 additions & 0 deletions Library/Homebrew/test/test_ARGV.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ def test_argv_formulae
assert_raises(FormulaUnavailableError) { @argv.formulae }
end

def test_argv_casks
@argv.unshift 'mxcl'
assert_equal [], @argv.casks
end

def test_argv_kegs
keg = HOMEBREW_CELLAR + "mxcl/10.0"
keg.mkpath
Expand Down

0 comments on commit 6651fb8

Please sign in to comment.