diff options
author | Noah Kantrowitz <noah@coderanger.net> | 2018-06-23 21:38:32 -0700 |
---|---|---|
committer | Noah Kantrowitz <noah@coderanger.net> | 2018-06-23 21:38:32 -0700 |
commit | c3bda57fcef745b1c570a654e9a633dcf842b96f (patch) | |
tree | 8949c1a6cbe6a6873eac164bdf7a15e877e29460 /chef-config | |
parent | 36695a792c910feb9d834adb43faea372376cadf (diff) | |
download | chef-c3bda57fcef745b1c570a654e9a633dcf842b96f.tar.gz |
Add support for a $CHEF_HOME environment variable and improve support for the existing $KNIFE_HOME.
Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
Diffstat (limited to 'chef-config')
-rw-r--r-- | chef-config/lib/chef-config/path_helper.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/chef-config/lib/chef-config/path_helper.rb b/chef-config/lib/chef-config/path_helper.rb index 6341ffe4e6..fbb413578a 100644 --- a/chef-config/lib/chef-config/path_helper.rb +++ b/chef-config/lib/chef-config/path_helper.rb @@ -172,6 +172,18 @@ module ChefConfig Pathname.new(cleanpath(to)).relative_path_from(Pathname.new(cleanpath(from))) end + # Set the project-specific home directory environment variable. + # + # This can be used to allow per-tool home directory aliases like $KNIFE_HOME. + # + # @param [env_var] Key for an environment variable to use. + # @return [nil] + def self.per_tool_home_environment=(env_var) + @@per_tool_home_environment = env_var + # Reset this in case .home was already called. + @@home_dir = nil + end + # Retrieves the "home directory" of the current user while trying to ascertain the existence # of said directory. The path returned uses / for all separators (the ruby standard format). # If the home directory doesn't exist or an error is otherwise encountered, nil is returned. @@ -185,7 +197,9 @@ module ChefConfig # Home-path discovery is performed once. If a path is discovered, that value is memoized so # that subsequent calls to home_dir don't bounce around. # - # See self.all_homes. + # @see all_homes + # @param args [Array<String>] Path components to look for under the home directory. + # @return [String] def self.home(*args) @@home_dir ||= all_homes { |p| break p } if @@home_dir @@ -203,6 +217,8 @@ module ChefConfig # if no block is provided. def self.all_homes(*args) paths = [] + paths << ENV[@@per_tool_home_environment] if defined?(@@per_tool_home_environment) && @@per_tool_home_environment && ENV[@@per_tool_home_environment] + paths << ENV["CHEF_HOME"] if ENV["CHEF_HOME"] if ChefConfig.windows? # By default, Ruby uses the the following environment variables to determine Dir.home: # HOME |