diff options
author | Tim Smith <tsmith@chef.io> | 2021-01-14 09:41:57 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-14 09:41:57 -0800 |
commit | 6bf72ad10150205acf539d1309d644a23cc0926d (patch) | |
tree | 87a705f76ae53a4677bd59d1ac58ef05f03b19d9 | |
parent | 6260497fc626ae173f894271410e6780e7d66544 (diff) | |
parent | b545711d46c304195195ce371f240a3600339933 (diff) | |
download | chef-6bf72ad10150205acf539d1309d644a23cc0926d.tar.gz |
Merge pull request #10880 from jaymzh/chefshell-config
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/shell.rb | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/chef/shell.rb b/lib/chef/shell.rb index a425129fa8..5bff9c0292 100644 --- a/lib/chef/shell.rb +++ b/lib/chef/shell.rb @@ -25,6 +25,7 @@ require "pp" unless defined?(PP) require "etc" unless defined?(Etc) require "mixlib/cli" unless defined?(Mixlib::CLI) require "chef-utils/dist" unless defined?(ChefUtils::Dist) +require "chef-config/mixin/dot_d" require_relative "../chef" require_relative "version" @@ -211,6 +212,7 @@ module Shell class Options include Mixlib::CLI + include ChefConfig::Mixin::DotD def self.footer(text = nil) @footer = text if text @@ -341,15 +343,44 @@ module Shell # We have to nuke ARGV to make sure irb's option parser never sees it. # otherwise, IRB complains about command line switches it doesn't recognize. ARGV.clear + + # This code should not exist. + # We should be using Application::Client and then calling load_config_file + # which does all this properly. However this will do for now. config[:config_file] = config_file_for_shell_mode(environment) config_msg = config[:config_file] || "none (standalone session)" puts "loading configuration: #{config_msg}" - Chef::Config.from_file(config[:config_file]) if !config[:config_file].nil? && File.exist?(config[:config_file]) && File.readable?(config[:config_file]) + + # load the config (if we have one) + if !config[:config_file].nil? + if File.exist?(config[:config_file]) && File.readable?(config[:config_file]) + Chef::Config.from_file(config[:config_file]) + end + + # even if we couldn't load that, we need to tell Chef::Config what + # the file was so it sets confdir and d_dir and such properly + Chef::Config[:config_file] = config[:config_file] + + # now attempt to load any relevant dot-dirs + load_dot_d(Chef::Config[:client_d_dir]) if Chef::Config[:client_d_dir] + end + + # finally merge command-line options in Chef::Config.merge!(config) end private + # shamelessly lifted from application.rb + def apply_config(config_content, config_file_path) + Chef::Config.from_string(config_content, config_file_path) + rescue Exception => error + logger.fatal("Configuration error #{error.class}: #{error.message}") + filtered_trace = error.backtrace.grep(/#{Regexp.escape(config_file_path)}/) + filtered_trace.each { |line| logger.fatal(" " + line ) } + raise Chef::Exceptions::ConfigurationError.new("Aborting due to error in '#{config_file_path}': #{error}") + end + def config_file_for_shell_mode(environment) dot_chef_dir = Chef::Util::PathHelper.home(".chef") if config[:config_file] |