diff options
| author | Xu Cheng | 2016-01-02 23:08:51 +0800 |
|---|---|---|
| committer | Xu Cheng | 2016-01-03 21:00:11 +0800 |
| commit | 66c0b06d72bb55e1ac288a69336ae858095e5c32 (patch) | |
| tree | 6650cd8bcc4e4cb5d1a949451e62f656afe7e249 /Library | |
| parent | f29699f77c8f52c1ec5de19bb115ed784611613b (diff) | |
| download | brew-66c0b06d72bb55e1ac288a69336ae858095e5c32.tar.bz2 | |
utils: add which_all
Similar to which, except it returns all of paths where binary is found.
i.e. it's equivalent to `which -a`.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/requirement.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/utils.rb | 13 |
2 files changed, 17 insertions, 0 deletions
diff --git a/Library/Homebrew/requirement.rb b/Library/Homebrew/requirement.rb index 91eedd72d..0aa4ed78d 100644 --- a/Library/Homebrew/requirement.rb +++ b/Library/Homebrew/requirement.rb @@ -134,6 +134,10 @@ class Requirement super(cmd, ORIGINAL_PATHS.join(File::PATH_SEPARATOR)) end + def which_all(cmd) + super(cmd, ORIGINAL_PATHS.join(File::PATH_SEPARATOR)) + end + class << self include BuildEnvironmentDSL diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 50e226faa..a709827a5 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -361,6 +361,19 @@ def which(cmd, path = ENV["PATH"]) nil end +def which_all(cmd, path = ENV["PATH"]) + path.split(File::PATH_SEPARATOR).map do |p| + begin + pcmd = File.expand_path(cmd, p) + rescue ArgumentError + # File.expand_path will raise an ArgumentError if the path is malformed. + # See https://github.com/Homebrew/homebrew/issues/32789 + next + end + Pathname.new(pcmd) if File.file?(pcmd) && File.executable?(pcmd) + end.compact.uniq +end + def which_editor editor = ENV.values_at("HOMEBREW_EDITOR", "VISUAL", "EDITOR").compact.first return editor unless editor.nil? |
