summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNolan Davidson <nolan.davidson@gmail.com>2014-08-22 23:07:15 -0400
committerLamont Granquist <lamont@scriptkiddie.org>2014-09-10 14:59:09 -0700
commitdad4783c04367bebfa5ecb295c59f8cb97d5e3bb (patch)
tree3fff173d127e056d4bd16bbb6d8188b883ef5333
parentd2920164deb5e8c6b6b4792e7c400f731e798420 (diff)
downloadchef-dad4783c04367bebfa5ecb295c59f8cb97d5e3bb.tar.gz
Fixed Issue 1882 by printing usage when chef-apply is run with no arguments
-rw-r--r--lib/chef/application/apply.rb9
-rw-r--r--spec/unit/application/apply.rb12
2 files changed, 18 insertions, 3 deletions
diff --git a/lib/chef/application/apply.rb b/lib/chef/application/apply.rb
index ab35b35389..95c937905b 100644
--- a/lib/chef/application/apply.rb
+++ b/lib/chef/application/apply.rb
@@ -134,8 +134,13 @@ class Chef::Application::Apply < Chef::Application
@recipe_text = STDIN.read
temp_recipe_file
else
- @recipe_filename = ARGV[0]
- @recipe_text,@recipe_fh = read_recipe_file @recipe_filename
+ if ARGV[0]
+ @recipe_filename = ARGV[0]
+ @recipe_text,@recipe_fh = read_recipe_file @recipe_filename
+ else
+ puts opt_parser
+ Chef::Application.exit! "No recipe file provided", 1
+ end
end
recipe,run_context = get_recipe_and_run_context
recipe.instance_eval(@recipe_text, @recipe_filename, 1)
diff --git a/spec/unit/application/apply.rb b/spec/unit/application/apply.rb
index 32c98c6ed6..62a53c2a31 100644
--- a/spec/unit/application/apply.rb
+++ b/spec/unit/application/apply.rb
@@ -20,7 +20,7 @@ require 'spec_helper'
describe Chef::Application::Apply do
before do
- @app = Chef::Application::Recipe.new
+ @app = Chef::Application::Apply.new
@app.stub(:configure_logging).and_return(true)
@recipe_text = "package 'nyancat'"
Chef::Config[:solo] = true
@@ -73,4 +73,14 @@ describe Chef::Application::Apply do
@recipe_fh.path.should == @app.instance_variable_get(:@recipe_filename)
end
end
+ describe "recipe_file_arg" do
+ before do
+ ARGV.clear
+ end
+ it "should exit and log message" do
+ Chef::Log.should_receive(:debug).with(/^No recipe file provided/)
+ lambda { @app.run }.should raise_error(SystemExit) { |e| e.status.should == 1 }
+ end
+
+ end
end