Created
March 4, 2013 16:19
-
-
Save chrisroberts/5083420 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module KnifeConfigHack | |
def hacked_parse_options(*args) | |
configure_chef | |
configure_from_file_settings! | |
original_parse_options(*args) | |
end | |
def configure_from_file_settings! | |
if(Chef::Config[:knife]) | |
self.class.options.keys.each do |key| | |
config[key] = Chef::Config[:knife][key] if Chef::Config[:knife].has_key?(key) | |
end | |
end | |
end | |
def hacked_run(*args) | |
config = nil | |
parse_options(ARGV) | |
original_run(*args) | |
end | |
class << self | |
def included(base) | |
base.class_eval do | |
alias_method :original_parse_options, :parse_options | |
alias_method :parse_options, :hacked_parse_options | |
alias_method :original_run, :run | |
alias_method :run, :hacked_run | |
end | |
end | |
def extended(base) | |
base.instance_eval do | |
alias :original_parse_options :parse_options | |
alias :parse_options :hacked_parse_options | |
alias :original_run :run | |
alias :run :hacked_run | |
end | |
end | |
end | |
end | |
Chef::Knife.constants.map do |c| | |
k = Chef::Knife.const_get(c) | |
k if k.is_a?(Class) && k.instance_methods.map(&:to_sym).include?(:run) && k.name.split('::').last.start_with?('Ec') | |
end.compact.each do |klass| | |
unless(klass.instance_methods.map(&:to_sym).include?(:hacked_run)) | |
klass.send(:include, KnifeConfigHack) | |
end | |
ObjectSpace.each_object(klass) do |obj| | |
obj.extend(KnifeConfigHack) unless obj.methods.map(&:to_sym).include?(:hacked_run) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment