aboutsummaryrefslogtreecommitdiff
path: root/lib/leap_cli/util.rb
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-02-26 16:59:59 -0800
committerelijah <elijah@riseup.net>2013-02-26 16:59:59 -0800
commit37ce2bddb9556cbad0b4b13e37df8e1286a0375e (patch)
tree444196c2964bccbe2078c3994aa69fcdaa145c83 /lib/leap_cli/util.rb
parentb415db1a6bfd08856d299e527bf6b16e3fd220b2 (diff)
downloadleap_cli-37ce2bddb9556cbad0b4b13e37df8e1286a0375e.tar.gz
leap_cli-37ce2bddb9556cbad0b4b13e37df8e1286a0375e.tar.bz2
try to issue better exit codes. still not perfect.
Diffstat (limited to 'lib/leap_cli/util.rb')
-rw-r--r--lib/leap_cli/util.rb13
1 files changed, 9 insertions, 4 deletions
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