Method: Methadone::SH#sh!
- Defined in:
- lib/methadone/sh.rb
#sh!(command, options = {}, &block) ⇒ Object
Run a command, throwing an exception if the command exited nonzero. Otherwise, behaves exactly like #sh.
- options
-
options hash, responding to:
:expected
-
same as for #sh
:on_fail
-
a custom error message. This allows you to have your app exit on shell command failures, but customize the error message that they see.
Raises Methadone::FailedCommandError if the command exited nonzero.
Examples:
sh!("rsync foo bar")
# => if command fails, app exits and user sees: "error: Command 'rsync foo bar' exited 12"
sh!("rsync foo bar", :on_fail => "Couldn't rsync, check log for details")
# => if command fails, app exits and user sees: "error: Couldn't rsync, check log for details
139 140 141 142 143 144 145 146 |
# File 'lib/methadone/sh.rb', line 139 def sh!(command,={},&block) sh(command,,&block).tap do |exitstatus| process_status = Methadone::ProcessStatus.new(exitstatus,[:expected]) unless process_status.success? raise Methadone::FailedCommandError.new(exitstatus,command,[:on_fail]) end end end |