diff options
author | Marc A. Paradise <marc.paradise@gmail.com> | 2019-06-07 15:39:36 -0400 |
---|---|---|
committer | Marc A. Paradise <marc.paradise@gmail.com> | 2019-06-07 15:39:36 -0400 |
commit | 023c89e326251e8c2f063aa6f4ecd787cd35316f (patch) | |
tree | 22ad7a01ace4af3146b44223debeeeaa08467950 | |
parent | 47eb2730d081be1ef02b81e25a19187a4cd5703d (diff) | |
download | mixlib-cli-023c89e326251e8c2f063aa6f4ecd787cd35316f.tar.gz |
Don't explode when there are unknown keys in 'config'deprecation-fix-unknown-keys
Update handle_deprecated_options to be graceful when
'config' has been modified externally to contain unknown keys.
Signed-off-by: Marc A. Paradise <marc.paradise@gmail.com>
-rw-r--r-- | lib/mixlib/cli.rb | 7 | ||||
-rw-r--r-- | spec/mixlib/cli_spec.rb | 12 |
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/mixlib/cli.rb b/lib/mixlib/cli.rb index 1a83a11..d0c1c67 100644 --- a/lib/mixlib/cli.rb +++ b/lib/mixlib/cli.rb @@ -392,11 +392,16 @@ module Mixlib merge_in_values = {} config.each_key do |opt_key| opt_cfg = options[opt_key] + # Deprecated entries do not have defaults so no matter what # separate_default_options are set, if we see a 'config' # entry that contains a deprecated indicator, then the option was # explicitly provided by the caller. - next unless opt_cfg[:deprecated] + # + # opt_cfg may not exist if an inheriting application + # has directly inserted values info config. + next unless opt_cfg && opt_cfg[:deprecated] + replacement_key = opt_cfg[:replacement] if replacement_key # This is the value passed into the deprecated flag. We'll use diff --git a/spec/mixlib/cli_spec.rb b/spec/mixlib/cli_spec.rb index acc10f8..46795aa 100644 --- a/spec/mixlib/cli_spec.rb +++ b/spec/mixlib/cli_spec.rb @@ -326,6 +326,18 @@ describe Mixlib::CLI do TestCLI.option(:option_c, short: "-c ARG") end + context "when someone injects an unexpected value into 'config'" do + before do + cli.config[:surprise] = true + end + it "parses and preserves both known and unknown config values" do + cli.parse_options(%w{--option-a}) + expect(cli.config[:surprise]).to eql true + expect(cli.config[:option_a]).to eql true + end + + end + context "when the deprecated option has a replacement" do context "and a value_mapper is provided" do |