Module: ShellHelpers::ExitNow

Included in:
ShellHelpers
Defined in:
lib/shell_helpers/sh.rb

Overview

Provides #exit_now! You might mix this into your business logic classes if they will need to exit the program with a human-readable error message.

Instance Method Summary collapse

Instance Method Details

#exit_now!(exit_code, message = nil) ⇒ Object

Call this to exit the program immediately with the given error code and message.

exit_code

exit status you'd like to exit with

message

message to display to the user explaining the problem

If exit_code is a String and message is omitted, exit_code will

Examples

	exit_now!(4,"Oh noes!")
		# => exit app with status 4 and show the user "Oh noes!" on stderr
	exit_now!("Oh noes!")
		# => exit app with status 1 and show the user "Oh noes!" on stderr
	exit_now!(4)
		# => exit app with status 4 and dont' give the user a message (how rude of you)


51
52
53
54
55
56
57
# File 'lib/shell_helpers/sh.rb', line 51

def exit_now!(exit_code,message=nil)
	if exit_code.kind_of?(String) && message.nil?
		raise ExitError.new(1,exit_code)
	else
		raise ExitError.new(exit_code,message)
	end
end