Skip to content

Commit

Permalink
always reject uninstallable formulae
Browse files Browse the repository at this point in the history
  • Loading branch information
bfontaine committed Aug 1, 2015
1 parent 5a236a0 commit 6604d6b
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions cmd/brew-which-formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#
#

# brew
require "formula"
require "extend/ARGV.rb"

TAP_RE = %r(^.+?/[^/]+)
Expand All @@ -21,16 +21,16 @@ def matches(cmd)
Utils.popen_read("grep", cmd, LIST_PATH).chomp.split(/\n/)
end

def reject_formula?(name)
f = Formula[name] rescue nil
f.nil? || f.installed? || f.requirements.any? { |r| r.required? && !r.satisfied? }

This comment has been minimized.

Copy link
@xu-cheng

xu-cheng Aug 1, 2015

Member

Unsatisfied requirement doesn't mean uninstallable, right?

This comment has been minimized.

Copy link
@bfontaine

bfontaine Aug 1, 2015

Author Contributor

Oh, right. I should test for unstatisfiable requirements then, like MaximumMacOSRequirement.

end

# Print a small text explaining how to get 'cmd' by installing 'formula'. Note
# that it'll still suggest to install the formula if it's already installed but
# unlinked.
def explain_formula_install(cmd, formula)
require "formula"
f = Formula[formula] rescue nil
unless f.nil?
return if f.installed?
return if f.requirements.any? { |r| r.required? && !r.satisfied? }
end
return if reject_formula? formula
puts <<-EOS
The program '#{cmd}' is currently not installed. You can install it by typing:
brew install #{formula}
Expand All @@ -40,6 +40,8 @@ def explain_formula_install(cmd, formula)
# Print a small text explaining how to get 'cmd' by installing one of the given
# formulae.
def explain_formulae_install(cmd, formulae)
formulae.reject! { |f| reject_formula? f }
return if formulae.empty?
return explain_formula_install(cmd, formulae.first) if formulae.size == 1
puts <<-EOS.undent
The program '#{cmd}' can be found in the following formulae:
Expand Down

0 comments on commit 6604d6b

Please sign in to comment.