- From: Jesse Campbell <
>
- To:
- Subject: [chef-dev] options in knife plugins
- Date: Wed, 4 Apr 2012 16:47:50 -0400
I would like to be able to allow users to enter options on the command
line, or in a config file, failing back to defaults otherwise.
Here's how I have it right now:
in the plugin file:
option :recursive,
:long => "--recursive",
:short => "-r",
:description => "Recurse down through sub-folders"
def get_config(key)
key = key.to_sym
config[key] || Chef::Config[:knife][key]
end
in knife.rb:
knife[:recursive] = true
I can set the :default option, but it will cause the default to
override the knife.rb always.
As an alternative, I can create a new defaults[] hash like so:
defaults[:recursive] = true
def get_config(key)
key = key.to_sym
config[key] || Chef::Config[:knife][key] || defaults[key]
end
Is there a better way? Is there some automated correlation on the back
end that I haven't yet found between options, config[], and
Chef::Config[] ?
Thanks!
- [chef-dev] options in knife plugins, Jesse Campbell, 04/04/2012
Archive powered by MHonArc 2.6.16.