Skip to content

Instantly share code, notes, and snippets.

@werebus
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save werebus/b1ea94fd3e12ea794586 to your computer and use it in GitHub Desktop.
Save werebus/b1ea94fd3e12ea794586 to your computer and use it in GitHub Desktop.
Getting knife configuration into chef-dk generator
#<chef_repo>/code_generator/libraries/config_defaults.rb
#Pull in all of the values defined in the `chefdk` context in knife.rb
Chef::Config[:chefdk].configuration.each do |config_key, value|
ChefDK::Generator.context.send("#{config_key}=", value)
end
#<chef_repo>/.chef/knife.rb
require 'optparse'
# Other knife stuff
if config_contexts.include? :chefdk
chefdk.generator_cookbook File.join(current_dir, '..', 'code_generator')
chefdk.copyright_holder "UMass Transit Service"
chefdk.email 'transit-it@admin.umass.edu'
chefdk.license 'mit'
OptionParser.new do |opts|
opts.on('-C', '--copyright HOLDER') do |c|
chefdk.copyright_holder c
end
opts.on('-m', '--email EMAIL') do |m|
chefdk.email m
end
opts.on('-I', '--license LICENSE') do |i|
chefdk.license i
end
end.parse!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment