summaryrefslogtreecommitdiff
path: root/lib/chef/application.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@chef.io>2016-10-18 15:39:15 -0700
committerdanielsdeleo <dan@chef.io>2016-10-18 16:13:14 -0700
commit466bfbf2db3c02c0f5263f0e93e12baf1de69832 (patch)
treefe21e3d81554bcfb30b50033ab9d5921f69c5355 /lib/chef/application.rb
parent488dc6137ec3ce77e35ffd865fb1758c8403ad09 (diff)
downloadchef-466bfbf2db3c02c0f5263f0e93e12baf1de69832.tar.gz
Implement `--config-option` CLI opt for knifedan/config-option-in-knife
The `--config-option` CLI option allows setting any `Chef::Config` setting on the command line, which allows applications to be used without a configuration file even if a desired config option does not have a corresponding CLI option. This CLI option was present in the help output for knife but was not actually implemented. Moving the behavior into chef-config allows us to use it for both `chef-client` and `knife`. Signed-off-by: Daniel DeLeo <dan@chef.io>
Diffstat (limited to 'lib/chef/application.rb')
-rw-r--r--lib/chef/application.rb22
1 files changed, 7 insertions, 15 deletions
diff --git a/lib/chef/application.rb b/lib/chef/application.rb
index f9735a3769..7f15859c8f 100644
--- a/lib/chef/application.rb
+++ b/lib/chef/application.rb
@@ -28,7 +28,6 @@ require "mixlib/cli"
require "tmpdir"
require "rbconfig"
require "chef/application/exit_code"
-require "yaml"
class Chef
class Application
@@ -111,20 +110,13 @@ class Chef
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.
- memo[key.to_sym] = YAML.safe_load(value)
- memo
- end
- Chef::Config.merge!(extra_parsed_options)
- end
+ apply_extra_config_options(extra_config_options)
+ end
+
+ def apply_extra_config_options(extra_config_options)
+ Chef::Config.apply_extra_config_options(extra_config_options)
+ rescue ChefConfig::UnparsableConfigOption => e
+ Chef::Application.fatal!(e.message)
end
def set_specific_recipes