summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-03-09 19:52:51 -0700
committerTim Smith <tsmith84@gmail.com>2020-04-16 15:23:29 -0700
commit25038cc59f36d1b1e76ed8470ee1637d6960d302 (patch)
tree5587333669f4472f8eec899f997d56b190e57a8b
parent20de02f564a5fea6b739796d9ffbcf119383401c (diff)
downloadchef-25038cc59f36d1b1e76ed8470ee1637d6960d302.tar.gz
Support working with package aliases
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/provider/package/homebrew.rb33
1 files changed, 28 insertions, 5 deletions
diff --git a/lib/chef/provider/package/homebrew.rb b/lib/chef/provider/package/homebrew.rb
index 360ebcc864..bde2c5fb43 100644
--- a/lib/chef/provider/package/homebrew.rb
+++ b/lib/chef/provider/package/homebrew.rb
@@ -101,6 +101,25 @@ class Chef
end
end
+ #
+ # Return the package information given a package name or package alias
+ #
+ # @param [String] name_or_alias The name of the package or its alias
+ #
+ # @return [Hash] Package information
+ #
+ def package_info(package_name)
+ # return the package name if it's in the brew info hash
+ return brew_info[package_name] if brew_info[package_name]
+
+ # check each item in the hash to see if we were passed an alias
+ brew_info.each_value do |p|
+ return p if p["aliases"].include?(package_name)
+ end
+
+ {}
+ end
+
# Some packages (formula) are "keg only" and aren't linked,
# because multiple versions installed can cause conflicts. We
# handle this by using the last installed version as the
@@ -111,14 +130,16 @@ class Chef
#
# @returns [String] package version
def installed_version(i)
- if brew_info[i]["keg_only"]
- if brew_info[i]["installed"].empty?
+ p_data = package_info(i)
+
+ if p_data["keg_only"]
+ if p_data["installed"].empty?
nil
else
- brew_info[i]["installed"].last["version"]
+ p_data["installed"].last["version"]
end
else
- brew_info[i]["linked_keg"]
+ p_data["linked_keg"]
end
end
@@ -136,7 +157,9 @@ class Chef
#
# @returns [String] package version
def available_version(i)
- brew_info[i]["versions"]["stable"]
+ p_data = package_info(i)
+
+ p_data["versions"]["stable"]
end
private