summaryrefslogtreecommitdiff
path: root/lib/chef/application.rb
diff options
context:
space:
mode:
authorNoah Kantrowitz <noah@coderanger.net>2016-06-21 16:04:01 -0700
committerNoah Kantrowitz <noah@coderanger.net>2016-06-21 16:07:59 -0700
commit267cd39a17454a17cce7eeef8aea292aec4647fc (patch)
tree10aa44ef2572c5e4786992314be1dc55b52becc7 /lib/chef/application.rb
parent8693be1d64b06b93fb357ac96588b17a6ea64579 (diff)
downloadchef-267cd39a17454a17cce7eeef8aea292aec4647fc.tar.gz
First pass on --config-option handling.
Diffstat (limited to 'lib/chef/application.rb')
-rw-r--r--lib/chef/application.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/chef/application.rb b/lib/chef/application.rb
index f8df71f723..50249e0054 100644
--- a/lib/chef/application.rb
+++ b/lib/chef/application.rb
@@ -108,7 +108,32 @@ class Chef
config_content = config_fetcher.read_config
apply_config(config_content, config[:config_file])
end
+ extra_config_options = config.delete(:config_option)
Chef::Config.merge!(config)
+ if extra_config_options
+ extra_parsed_options = extra_config_options.inject({}) do |memo, option|
+ # Sanity check value.
+ Chef::Application.fatal!("Unparsable config option #{option.inspect}") if option.empty? || !option.include?("=")
+ # Split including whitespace if someone does truly odd like
+ # --config-option "foo = bar"
+ key, value = option.split(/\s*=\s*/, 2)
+ # Call to_sym because Chef::Config expects only symbol keys. Also
+ # runs a simple parse on the string for some common types. Not using
+ # a YAML parser or similar because security. Could maybe use JSON?
+ memo[key.to_sym] = case value
+ when "true"
+ true
+ when "false"
+ false
+ when /^\d+$/
+ value.to_i
+ else
+ value
+ end
+ memo
+ end
+ Chef::Config.merge!(extra_parsed_options)
+ end
end
def set_specific_recipes