summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2019-10-28 12:01:28 -0700
committerGitHub <noreply@github.com>2019-10-28 12:01:28 -0700
commit78a5ac40600e2e8c89b8e11ff58f1104a9c836b3 (patch)
tree375f6071e57161892ff7429d8ec19920da74c644
parentd0908f4555b436eb74bbfee1a050a7cc84550aed (diff)
parentb3ec36bf24c462c1505f1e63ae2561ea809c4402 (diff)
downloadchef-78a5ac40600e2e8c89b8e11ff58f1104a9c836b3.tar.gz
Merge pull request #9032 from MsysTechnologiesllc/VSingh/fix-knife-cookbook-metadata-from-file-name-args
Fix knife cookbook metadata from file name args
-rw-r--r--lib/chef/knife/cookbook_metadata_from_file.rb6
-rw-r--r--spec/unit/knife/cookbook_metadata_from_file_spec.rb7
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/chef/knife/cookbook_metadata_from_file.rb b/lib/chef/knife/cookbook_metadata_from_file.rb
index 62d0f24324..42f8acba56 100644
--- a/lib/chef/knife/cookbook_metadata_from_file.rb
+++ b/lib/chef/knife/cookbook_metadata_from_file.rb
@@ -31,6 +31,12 @@ class Chef
banner "knife cookbook metadata from file FILE (options)"
def run
+ if @name_args.length < 1
+ show_usage
+ ui.fatal("You must specify the FILE.")
+ exit(1)
+ end
+
file = @name_args[0]
cookbook = File.basename(File.dirname(file))
diff --git a/spec/unit/knife/cookbook_metadata_from_file_spec.rb b/spec/unit/knife/cookbook_metadata_from_file_spec.rb
index 274eb5e167..69dbac7ac7 100644
--- a/spec/unit/knife/cookbook_metadata_from_file_spec.rb
+++ b/spec/unit/knife/cookbook_metadata_from_file_spec.rb
@@ -40,6 +40,13 @@ describe Chef::Knife::CookbookMetadataFromFile do
end
describe "run" do
+ it "should print usage and exit when a FILE is not provided" do
+ @knife.name_args = []
+ expect(@knife).to receive(:show_usage)
+ expect(@knife.ui).to receive(:fatal).with(/You must specify the FILE./)
+ expect { @knife.run }.to raise_error(SystemExit)
+ end
+
it "should determine cookbook name from path" do
expect(@md).to receive(:name).with(no_args)
expect(@md).to receive(:name).with("quick_start")