diff options
| author | Jack Nagel | 2012-05-07 20:32:04 -0500 |
|---|---|---|
| committer | Jack Nagel | 2012-05-07 21:05:47 -0500 |
| commit | 68124d481f7938f3bf280fb92d370a0de9a9b80f (patch) | |
| tree | f90db02fcdad95975fb43f830343d014563ced16 /Library | |
| parent | fa1edd684653e324d36c431fa8bc33b95e651f9e (diff) | |
| download | brew-68124d481f7938f3bf280fb92d370a0de9a9b80f.tar.bz2 | |
Unify 'which' and which_s' utility methods
'which' only returns a Pathname or nil, and doesn't care about anything
sent to stderr, so just silence it by default and combine the two
methods.
Closes Homebrew/homebrew#12115.
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/cmd/doctor.rb | 12 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/update.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/versions.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/download_strategy.rb | 10 | ||||
| -rw-r--r-- | Library/Homebrew/utils.rb | 15 |
5 files changed, 18 insertions, 23 deletions
diff --git a/Library/Homebrew/cmd/doctor.rb b/Library/Homebrew/cmd/doctor.rb index b4c99a7e6..1940ff272 100644 --- a/Library/Homebrew/cmd/doctor.rb +++ b/Library/Homebrew/cmd/doctor.rb @@ -633,7 +633,7 @@ def check_for_multiple_volumes end def check_for_git - unless which_s "git" then <<-EOS.undent + unless which "git" then <<-EOS.undent Git could not be found in your PATH. Homebrew uses Git for several internal functions, and some formulae use Git checkouts instead of stable tarballs. You may want to install Git: @@ -643,7 +643,7 @@ def check_for_git end def check_git_newline_settings - return unless which_s "git" + return unless which "git" autocrlf = `git config --get core.autocrlf`.chomp safecrlf = `git config --get core.safecrlf`.chomp @@ -774,7 +774,7 @@ def check_missing_deps end def check_git_status - return unless which_s "git" + return unless which "git" HOMEBREW_REPOSITORY.cd do unless `git status -s -- Library/Homebrew/ 2>/dev/null`.chomp.empty? then <<-EOS.undent You have uncommitted modifications to Homebrew's core. @@ -803,7 +803,7 @@ end def check_git_version # see https://github.com/blog/642-smart-http-support - return unless which_s "git" + return unless which "git" `git --version`.chomp =~ /git version (\d)\.(\d)\.(\d)/ if $2.to_i < 6 or $2.to_i == 6 and $3.to_i < 6 then <<-EOS.undent @@ -815,7 +815,7 @@ def check_git_version end def check_for_enthought_python - if which_s "enpkg" then <<-EOS.undent + if which "enpkg" then <<-EOS.undent Enthought Python was found in your PATH. This can cause build problems, as this software installs its own copies of iconv and libxml2 into directories that are picked up by @@ -825,7 +825,7 @@ def check_for_enthought_python end def check_for_bad_python_symlink - return unless which_s "python" + return unless which "python" # Indeed Python --version outputs to stderr (WTF?) `python --version 2>&1` =~ /Python (\d+)\./ unless $1 == "2" then <<-EOS.undent diff --git a/Library/Homebrew/cmd/update.rb b/Library/Homebrew/cmd/update.rb index 26edaf204..428014291 100644 --- a/Library/Homebrew/cmd/update.rb +++ b/Library/Homebrew/cmd/update.rb @@ -4,7 +4,7 @@ require 'cmd/untap' module Homebrew extend self def update - abort "Please `brew install git' first." unless which_s "git" + abort "Please `brew install git' first." unless which "git" # ensure GIT_CONFIG is unset as we need to operate on .git/config ENV.delete('GIT_CONFIG') diff --git a/Library/Homebrew/cmd/versions.rb b/Library/Homebrew/cmd/versions.rb index ba312ab6f..267551106 100644 --- a/Library/Homebrew/cmd/versions.rb +++ b/Library/Homebrew/cmd/versions.rb @@ -2,7 +2,7 @@ require 'formula' module Homebrew extend self def versions - raise "Please `brew install git` first" unless which_s "git" + raise "Please `brew install git` first" unless which "git" raise "Please `brew update' first" unless (HOMEBREW_REPOSITORY/".git").directory? raise FormulaUnspecifiedError if ARGV.named.empty? diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 3fcb4f270..41c4fdeb3 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -80,7 +80,7 @@ class CurlDownloadStrategy < AbstractDownloadStrategy safe_system '/usr/bin/tar', 'xf', @tarball_path chdir when :xz - raise "You must install XZutils: brew install xz" unless which_s "xz" + raise "You must install XZutils: brew install xz" unless which "xz" safe_system "xz -dc \"#{@tarball_path}\" | /usr/bin/tar xf -" chdir when :pkg @@ -322,7 +322,7 @@ class GitDownloadStrategy < AbstractDownloadStrategy end def fetch - raise "You must install Git: brew install git" unless which_s "git" + raise "You must install Git: brew install git" unless which "git" ohai "Cloning #{@url}" @@ -455,7 +455,7 @@ class MercurialDownloadStrategy < AbstractDownloadStrategy def cached_location; @clone; end def fetch - raise "You must install Mercurial: brew install mercurial" unless which_s "hg" + raise "You must install Mercurial: brew install mercurial" unless which "hg" ohai "Cloning #{@url}" @@ -496,7 +496,7 @@ class BazaarDownloadStrategy < AbstractDownloadStrategy def cached_location; @clone; end def fetch - raise "You must install bazaar first" unless which_s "bzr" + raise "You must install bazaar first" unless which "bzr" ohai "Cloning #{@url}" unless @clone.exist? @@ -539,7 +539,7 @@ class FossilDownloadStrategy < AbstractDownloadStrategy def cached_location; @clone; end def fetch - raise "You must install fossil first" unless which_s "fossil" + raise "You must install fossil first" unless which "fossil" ohai "Cloning #{@url}" unless @clone.exist? diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 3ae8e1181..f5530c29f 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -147,9 +147,8 @@ def puts_columns items, star_items=[] end end -def which cmd, silent=false - cmd += " 2>/dev/null" if silent - path = `/usr/bin/which #{cmd}`.chomp +def which cmd + path = `/usr/bin/which #{cmd} 2>/dev/null`.chomp if path.empty? nil else @@ -157,19 +156,15 @@ def which cmd, silent=false end end -def which_s cmd - which cmd, true -end - def which_editor editor = ENV['HOMEBREW_EDITOR'] || ENV['EDITOR'] # If an editor wasn't set, try to pick a sane default return editor unless editor.nil? # Find Textmate - return 'mate' if which_s "mate" + return 'mate' if which "mate" # Find # BBEdit / TextWrangler - return 'edit' if which_s "edit" + return 'edit' if which "edit" # Default to vim return '/usr/bin/vim' end @@ -405,7 +400,7 @@ module MacOS extend self # Xcode 4.3 xc* tools hang indefinately if xcode-select path is set thus raise if `xcode-select -print-path 2>/dev/null`.chomp == "/" - raise unless which_s "xcodebuild" + raise unless which "xcodebuild" `xcodebuild -version 2>/dev/null` =~ /Xcode (\d(\.\d)*)/ raise if $1.nil? or not $?.success? $1 |
