diff options
author | Marc A. Paradise <marc.paradise@gmail.com> | 2019-05-01 10:22:24 -0400 |
---|---|---|
committer | Marc A. Paradise <marc.paradise@gmail.com> | 2019-05-03 17:30:08 -0400 |
commit | 3e3d4b1ac9c2aefd12eae60982eb321c1029ab44 (patch) | |
tree | 3a39230b475b007837d41f2f31c203cef6287e98 /lib/chef/knife.rb | |
parent | ba50ae6d20ef86ab39b9fa2eee982f929cd70c7e (diff) | |
download | chef-3e3d4b1ac9c2aefd12eae60982eb321c1029ab44.tar.gz |
Make config_source aware of cli defaults
If a value comes from CLI defaults, it will now return :cli_default.
This supports verifying deprecations when we need to know
if a value was actually supplied from the CLI, or if it was
defaulted from CLI options.
Since we have all of the original sources still available,
this also makes it so that we don't keep a separate hash
for tracking config source - we're just checking in the original
config sources in order that matches merge priority.
Signed-off-by: Marc A. Paradise <marc.paradise@gmail.com>
Diffstat (limited to 'lib/chef/knife.rb')
-rw-r--r-- | lib/chef/knife.rb | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb index da9c1ab1e9..4cd7cdb73c 100644 --- a/lib/chef/knife.rb +++ b/lib/chef/knife.rb @@ -344,13 +344,8 @@ class Chef # Chef::Config[:knife] would break the defaults in the cli that we would otherwise # overwrite. def config_file_settings - @key_sources = { cli: [], config: [] } cli_keys.each_with_object({}) do |key, memo| - if config.key?(key) - @key_sources[:cli] << key - end if Chef::Config[:knife].key?(key) - @key_sources[:config] << key memo[key] = Chef::Config[:knife][key] end end @@ -361,16 +356,28 @@ class Chef # config_file_settings - Chef::Config[:knife] sub-hash # config - mixlib-cli settings (accessor from the mixin) def merge_configs + # This is the config after user CLI options have been evaluated, and it contains only + # user-supplied values. + @original_config = config.dup # other code may have a handle to the config object, so use Hash#replace to deliberately # update-in-place. config.replace(default_config.merge(config_file_settings).merge(config)) end - # Return where a config key has been sourced, - # :cli, :config, or nil if the key is not set. + # + # Determine the source of a given configuration key + # + # @argument key [Symbol] a configuration key + # @return [Symbol,NilClass] return the source of the config key, + # one of: + # - :cli - this was explicitly provided on the CLI + # - :config - this came from Chef::Config[:knife] + # - :cli_default - came from a declared CLI `option`'s `default` value. + # - nil - if they key does not exist def config_source(key) - return :cli if @key_sources[:cli].include? key - return :config if @key_sources[:config].include? key + return :cli if @original_config.include? key + return :config if config_file_settings.key? key + return :cli_default if default_config.include? key nil end |