From 37ce2bddb9556cbad0b4b13e37df8e1286a0375e Mon Sep 17 00:00:00 2001 From: elijah Date: Tue, 26 Feb 2013 16:59:59 -0800 Subject: try to issue better exit codes. still not perfect. --- lib/leap_cli/util.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lib/leap_cli/util.rb') diff --git a/lib/leap_cli/util.rb b/lib/leap_cli/util.rb index b7c5e80..5bab424 100644 --- a/lib/leap_cli/util.rb +++ b/lib/leap_cli/util.rb @@ -12,6 +12,10 @@ module LeapCli ## QUITTING ## + def exit_status(code) + @exit_status = code + end + # # quit and print help # @@ -21,7 +25,7 @@ module LeapCli end # - # quit with a message that we are bailing out. + # exit with error code and with a message that we are bailing out. # def bail!(message=nil) if block_given? @@ -31,15 +35,15 @@ module LeapCli log 0, message end log 0, :bail, "" - raise SystemExit.new + raise SystemExit.new(@exit_status || 1) end # - # quit with no message + # quit with message, but no additional error or warning about bailing. # def quit!(message='') puts(message) - raise SystemExit.new + raise SystemExit.new(@exit_status || 0) end # @@ -72,6 +76,7 @@ module LeapCli cmd = cmd + " 2>&1" output = `#{cmd}` unless $?.success? + exit_status($?.exitstatus) bail! do log :run, cmd log :failed, "(exit #{$?.exitstatus}) #{output}", :indent => 1 -- cgit v1.2.3