diff options
author | Chris Roberts <chrisroberts.code@gmail.com> | 2012-10-17 16:30:56 -0700 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2013-01-11 16:04:24 -0800 |
commit | 416ef57a8e1a1b7effe2d2cf9ab940b8c6fdd6af (patch) | |
tree | faa910ab197857de1e024b009c639279efec7398 /lib/chef/knife.rb | |
parent | 962783a39ab3622afd4bd802bd04ffe6d066e737 (diff) | |
download | chef-416ef57a8e1a1b7effe2d2cf9ab940b8c6fdd6af.tar.gz |
Isolate knife config file location methodology. Use new locate method when configuring
Diffstat (limited to 'lib/chef/knife.rb')
-rw-r--r-- | lib/chef/knife.rb | 65 |
1 files changed, 38 insertions, 27 deletions
diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb index d8b0a169b6..a2db94604f 100644 --- a/lib/chef/knife.rb +++ b/lib/chef/knife.rb @@ -264,7 +264,7 @@ class Chef command_name_words = self.class.snake_case_name.split('_') configure_chef - configure_from_file_settings! + configure_from_file_settings! if allow_auto_knife_config? # Mixlib::CLI ignores the embedded name_args @name_args = parse_options(argv) @name_args.delete(command_name_words.join('-')) @@ -293,43 +293,54 @@ class Chef exit(1) end + def allow_auto_knife_config? + false + end + def configure_from_file_settings! - if(Chef::Config[:knife]) + unless(config[:config_file]) + locate_config_file + end + if(config[:config_file]) self.class.options.keys.each do |key| config[key] = Chef::Config[:knife][key] if Chef::Config[:knife].has_key?(key) end end end - def configure_chef - unless config[:config_file] - candidate_configs = [] + def locate_config_file + candidate_configs = [] - # Look for $KNIFE_HOME/knife.rb (allow multiple knives config on same machine) - if ENV['KNIFE_HOME'] - candidate_configs << File.join(ENV['KNIFE_HOME'], 'knife.rb') - end - # Look for $PWD/knife.rb - if Dir.pwd - candidate_configs << File.join(Dir.pwd, 'knife.rb') - end - # Look for $UPWARD/.chef/knife.rb - if self.class.chef_config_dir - candidate_configs << File.join(self.class.chef_config_dir, 'knife.rb') - end - # Look for $HOME/.chef/knife.rb - if ENV['HOME'] - candidate_configs << File.join(ENV['HOME'], '.chef', 'knife.rb') - end + # Look for $KNIFE_HOME/knife.rb (allow multiple knives config on same machine) + if ENV['KNIFE_HOME'] + candidate_configs << File.join(ENV['KNIFE_HOME'], 'knife.rb') + end + # Look for $PWD/knife.rb + if Dir.pwd + candidate_configs << File.join(Dir.pwd, 'knife.rb') + end + # Look for $UPWARD/.chef/knife.rb + if self.class.chef_config_dir + candidate_configs << File.join(self.class.chef_config_dir, 'knife.rb') + end + # Look for $HOME/.chef/knife.rb + if ENV['HOME'] + candidate_configs << File.join(ENV['HOME'], '.chef', 'knife.rb') + end - candidate_configs.each do | candidate_config | - candidate_config = File.expand_path(candidate_config) - if File.exist?(candidate_config) - config[:config_file] = candidate_config - break - end + candidate_configs.each do | candidate_config | + candidate_config = File.expand_path(candidate_config) + if File.exist?(candidate_config) + config[:config_file] = candidate_config + break end end + end + + def configure_chef + unless config[:config_file] + locate_config_file + end # Don't try to load a knife.rb if it doesn't exist. if config[:config_file] |