Options in knife plugins


#1

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!