diff options
author | danielsdeleo <dan@getchef.com> | 2014-11-13 13:00:37 -0800 |
---|---|---|
committer | danielsdeleo <dan@getchef.com> | 2014-11-13 15:22:43 -0800 |
commit | 103c7f0d6ca60f3c45f51cbbc504268614540544 (patch) | |
tree | 29e020beda297419d2b5b1bfeba301a362791248 /lib/chef/knife/core | |
parent | 2bcf0d41075cb6382fe11a10aa3e9dfcb7fd1504 (diff) | |
download | chef-103c7f0d6ca60f3c45f51cbbc504268614540544.tar.gz |
Merge branch 'chef-dk-227' into 11-stable
Diffstat (limited to 'lib/chef/knife/core')
-rw-r--r-- | lib/chef/knife/core/subcommand_loader.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/chef/knife/core/subcommand_loader.rb b/lib/chef/knife/core/subcommand_loader.rb index d2be1be2d3..f9b8f5008e 100644 --- a/lib/chef/knife/core/subcommand_loader.rb +++ b/lib/chef/knife/core/subcommand_loader.rb @@ -22,6 +22,9 @@ class Chef class Knife class SubcommandLoader + MATCHES_CHEF_GEM = %r{/chef-[\d]+\.[\d]+\.[\d]+}.freeze + MATCHES_THIS_CHEF_GEM = %r{/chef-#{Chef::VERSION}/}.freeze + attr_reader :chef_config_dir attr_reader :env @@ -122,6 +125,14 @@ class Chef subcommand_files = {} files.each do |file| rel_path = file[/(#{Regexp.escape File.join('chef', 'knife', '')}.*)\.rb/, 1] + + # When not installed as a gem (ChefDK/appbundler in particular), AND + # a different version of Chef is installed via gems, `files` will + # include some files from the 'other' Chef install. If this contains + # a knife command that doesn't exist in this version of Chef, we will + # get a LoadError later when we try to require it. + next if from_different_chef_version?(file) + subcommand_files[rel_path] = file end @@ -185,6 +196,19 @@ class Chef Dir[glob].map { |f| f.untaint } end + + def from_different_chef_version?(path) + matches_any_chef_gem?(path) && !matches_this_chef_gem?(path) + end + + def matches_any_chef_gem?(path) + path =~ MATCHES_CHEF_GEM + end + + def matches_this_chef_gem?(path) + path =~ MATCHES_THIS_CHEF_GEM + end + end end end |