Module: ProgramExitFromError
- Included in:
- Rake::ToolkitProgram::InvalidCommandLine, Rake::ToolkitProgram::NoCommand, Rake::ToolkitProgram::UnknownName, Rake::ToolkitProgram::WrongArgumentCount
- Defined in:
- lib/program_exit_from_error.rb
Overview
Idiomatic support for dealing with errors during CLI use
Rather than allowing an error to propagate to the top level of the interpreter, this module provides the #exit_program! method, which prints a message to STDERR and exits with an exit code of 1 (unless otherwise specified with .exit_with_code).
For debugging support, this module also exposes the #exit_code it would use to exit the program were #exit_program! called.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
32 33 34 |
# File 'lib/program_exit_from_error.rb', line 32 def self.included(klass) klass.extend(ClassMethods) end |
Instance Method Details
#exit_code ⇒ Object
44 45 46 |
# File 'lib/program_exit_from_error.rb', line 44 def exit_code self.class.instance_variable_get(:@exit_code) || 1 end |
#exit_program! ⇒ Object
48 49 50 51 |
# File 'lib/program_exit_from_error.rb', line 48 def exit_program! Kernel.exit(exit_code) end |
#print_error_message ⇒ Object
53 54 55 |
# File 'lib/program_exit_from_error.rb', line 53 def $stderr.puts("! ERROR: #{self}".bold.red) end |