summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSteven Danna <steve@chef.io>2015-10-22 09:31:51 +0100
committerSteven Danna <steve@chef.io>2015-10-29 14:03:22 +0000
commit5a1eb3e0cba55068aeaec03e0d2271e19a7ad4e7 (patch)
tree79e15822e47ddabe832fba95577a65eacbd15ff6 /lib
parent571891bf67667d0240edd632c36fc84cd0fc8bbe (diff)
downloadchef-5a1eb3e0cba55068aeaec03e0d2271e19a7ad4e7.tar.gz
Improve detection of ChefFS-based commands in `knife rehash`ssd/rehash-cheffs
ChefFS-based commands have a superclass (Chef::ChefFS::Knife) which defines its own inherited method that calls super. This breaks our detection of where the subcommand is defined since the file with the definition is no longer at the top of the call stack. This commit special-cases subclasses with a superclass of Chef::ChefFS::Knife to account for this. Fixes #4089
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/knife.rb15
1 files changed, 14 insertions, 1 deletions
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.