From b66553f4864e60400939ceeb9e2ef468be2198b5 Mon Sep 17 00:00:00 2001 From: Lance Ball Date: Fri, 22 Jun 2012 15:41:33 -0400 Subject: [PATCH] Exit with a non-zero value if site generation fails (issue #103) --- bin/awestruct | 5 ++++- lib/awestruct/cli/generate.rb | 1 + lib/awestruct/cli/invoker.rb | 5 ++++- lib/awestruct/cli/options.rb | 1 + spec/{awestruct_spec.rb => astruct_spec.rb} | 0 spec/invoker_spec.rb | 7 +++++-- 6 files changed, 15 insertions(+), 4 deletions(-) rename spec/{awestruct_spec.rb => astruct_spec.rb} (100%) diff --git a/bin/awestruct b/bin/awestruct index 39ba6046..05069ec2 100755 --- a/bin/awestruct +++ b/bin/awestruct @@ -5,4 +5,7 @@ $: << File.dirname(__FILE__) + '/../lib' require 'rubygems' require 'awestruct/cli/invoker' -Awestruct::CLI::Invoker.new( ARGV ).invoke! +invoker = Awestruct::CLI::Invoker.new( ARGV ) +invoker.invoke! + +invoker.success ? exit 0 : exit -1 diff --git a/lib/awestruct/cli/generate.rb b/lib/awestruct/cli/generate.rb index 07273a86..0834b434 100644 --- a/lib/awestruct/cli/generate.rb +++ b/lib/awestruct/cli/generate.rb @@ -20,6 +20,7 @@ def run() rescue =>e puts e puts e.backtrace + return false end end end diff --git a/lib/awestruct/cli/invoker.rb b/lib/awestruct/cli/invoker.rb index 15b3b6e2..cef2a9ff 100644 --- a/lib/awestruct/cli/invoker.rb +++ b/lib/awestruct/cli/invoker.rb @@ -16,6 +16,7 @@ class Invoker attr_reader :config attr_reader :profile + attr_reader :success def initialize(*options) options = options.flatten @@ -26,6 +27,7 @@ def initialize(*options) end @threads = [] @profile = nil + @success = true end def invoke! @@ -42,6 +44,7 @@ def invoke! invoke_auto() if ( options.auto ) wait_for_completion() + success end def load_profile() @@ -90,7 +93,7 @@ def invoke_force() end def invoke_generate() - Awestruct::CLI::Generate.new( config, options.profile, options.base_url, 'http://localhost:4242', options.force ).run + @success = Awestruct::CLI::Generate.new( config, options.profile, options.base_url, 'http://localhost:4242', options.force ).run end def invoke_deploy() diff --git a/lib/awestruct/cli/options.rb b/lib/awestruct/cli/options.rb index 3ff4e046..638eea60 100644 --- a/lib/awestruct/cli/options.rb +++ b/lib/awestruct/cli/options.rb @@ -4,6 +4,7 @@ module Awestruct module CLI + class Options attr_accessor :generate diff --git a/spec/awestruct_spec.rb b/spec/astruct_spec.rb similarity index 100% rename from spec/awestruct_spec.rb rename to spec/astruct_spec.rb diff --git a/spec/invoker_spec.rb b/spec/invoker_spec.rb index ac68bd40..681ff914 100644 --- a/spec/invoker_spec.rb +++ b/spec/invoker_spec.rb @@ -63,8 +63,11 @@ invoker.invoke! end - it "should return a non-zero value on failure" do - pending "A fix for issue #103" + it "should return false on failure" do + generator = mock + Awestruct::CLI::Generate.should_receive( :new ).and_return( generator ) + generator.should_receive( :run ).and_return( false ) + Awestruct::CLI::Invoker.new( '--generate' ).invoke!.should be_false end