diff options
author | Steven Danna <steve@chef.io> | 2015-10-29 14:42:25 +0000 |
---|---|---|
committer | Steven Danna <steve@chef.io> | 2015-10-29 14:42:25 +0000 |
commit | bc5a74f1561ada5062b979a0bd90024f59d86228 (patch) | |
tree | 79e15822e47ddabe832fba95577a65eacbd15ff6 | |
parent | 571891bf67667d0240edd632c36fc84cd0fc8bbe (diff) | |
parent | 5a1eb3e0cba55068aeaec03e0d2271e19a7ad4e7 (diff) | |
download | chef-bc5a74f1561ada5062b979a0bd90024f59d86228.tar.gz |
Merge pull request #4090 from chef/ssd/rehash-cheffs
Improve detection of ChefFS-based commands in `knife rehash`
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | lib/chef/knife.rb | 15 | ||||
-rw-r--r-- | spec/unit/knife_spec.rb | 8 |
3 files changed, 23 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 17608b32f8..2d434b3c28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ * [pr#3597](https://github.com/chef/chef/pull/3597) print STDOUT from the powershell_script * [pr#4091](https://github.com/chef/chef/pull/4091) Allow downloading of root_files in a chef repository * [pr#4112](https://github.com/chef/chef/pull/4112) Update knife bootstrap command to honor --no-color flag in chef-client run that is part of the bootstrap process. +* [pr#4090](https://github.com/chef/chef/pull/4090) Improve detection of ChefFS-based commands in `knife rehash` ## 12.5.1 diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb index 46e968827e..fed2ad4cfa 100644 --- a/lib/chef/knife.rb +++ b/lib/chef/knife.rb @@ -87,7 +87,16 @@ class Chef def self.inherited(subclass) unless subclass.unnamed? subcommands[subclass.snake_case_name] = subclass - subcommand_files[subclass.snake_case_name] += [caller[0].split(/:\d+/).first] + subcommand_files[subclass.snake_case_name] += + if subclass.superclass.to_s == "Chef::ChefFS::Knife" + # ChefFS-based commands have a superclass that defines an + # inhereited method which calls super. This means that the + # top of the call stack is not the class definition for + # our subcommand. Try the second entry in the call stack. + [path_from_caller(caller[1])] + else + [path_from_caller(caller[0])] + end end end @@ -221,6 +230,10 @@ class Chef OFFICIAL_PLUGINS = %w[ec2 rackspace windows openstack terremark bluebox] + def self.path_from_caller(caller_line) + caller_line.split(/:\d+/).first + end + # :nodoc: # Error out and print usage. probably because the arguments given by the # user could not be resolved to a subcommand. diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb index 022256f370..9e76ec59c4 100644 --- a/spec/unit/knife_spec.rb +++ b/spec/unit/knife_spec.rb @@ -117,6 +117,14 @@ describe Chef::Knife do expect(Chef::Knife.subcommands["super_awesome_command"]).to eq(SuperAwesomeCommand) end + it "records the location of ChefFS-based commands correctly" do + class AwesomeCheffsCommand < Chef::ChefFS::Knife + end + + Chef::Knife.load_commands + expect(Chef::Knife.subcommand_files["awesome_cheffs_command"]).to eq([__FILE__]) + end + it "guesses a category from a given ARGV" do Chef::Knife.subcommands_by_category["cookbook"] << :cookbook Chef::Knife.subcommands_by_category["cookbook site"] << :cookbook_site |