diff options
author | Tim Smith <tsmith@chef.io> | 2019-10-27 21:37:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-27 21:37:01 -0700 |
commit | 5cf8be51a26e89a07aa962db4b35f319b23c6fe7 (patch) | |
tree | 622f21cb62fb02295797c5d8e9df6e8fc40a4d9b | |
parent | 340ceac008bee94c053fd791175534a0b2a87ec2 (diff) | |
parent | ef2fbf960564d094e8c310dc3991d3fb477ddf30 (diff) | |
download | chef-5cf8be51a26e89a07aa962db4b35f319b23c6fe7.tar.gz |
Merge pull request #9026 from MsysTechnologiesllc/VSingh/format-option-with-better-message
Validate format option values using `in` attribute
-rw-r--r-- | lib/chef/application/knife.rb | 1 | ||||
-rw-r--r-- | spec/unit/application/knife_spec.rb | 17 |
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/chef/application/knife.rb b/lib/chef/application/knife.rb index 6f192a3e1f..10634176c4 100644 --- a/lib/chef/application/knife.rb +++ b/lib/chef/application/knife.rb @@ -114,6 +114,7 @@ class Chef::Application::Knife < Chef::Application short: "-F FORMAT", long: "--format FORMAT", description: "Which format to use for output.", + in: %w{summary text json yaml pp}, default: "summary" option :local_mode, diff --git a/spec/unit/application/knife_spec.rb b/spec/unit/application/knife_spec.rb index ea5083ac15..4b727eef93 100644 --- a/spec/unit/application/knife_spec.rb +++ b/spec/unit/application/knife_spec.rb @@ -77,6 +77,23 @@ describe Chef::Application::Knife do expect(Chef::Config[:color]).to be_truthy end + context "validate --format option" do + it "should set the default format summary" do + with_argv(*%w{noop knife command}) do + expect(@knife).to receive(:exit).with(0) + @knife.run + expect(@knife.default_config[:format]).to eq("summary") + end + end + + it "should raise the error for invalid value" do + with_argv(*%w{noop knife command -F abc}) do + expect(STDOUT).to receive(:puts).at_least(2).times + expect { @knife.run }.to raise_error(SystemExit) { |e| expect(e.status).to eq(2) } + end + end + end + context "when given fips flags" do context "when Chef::Config[:fips]=false" do before do |