Skip to content

Instantly share code, notes, and snippets.

@ktheory
Created June 4, 2013 21:52
Show Gist options
  • Save ktheory/5709936 to your computer and use it in GitHub Desktop.
Save ktheory/5709936 to your computer and use it in GitHub Desktop.
Monkeypatch for Thor `run_or_die` action
require 'thor'
module Thor
class CommandFailedError < Error; end
module Actions
# runs command, raises CommandFailedError unless exit status is 0.
def run_or_die(command, config={})
result = run(command, config)
if behavior == :invoke && $?.exitstatus != 0
message = "#{command} failed with %s" % ($?.exitstatus ? "exit status #{$?.exitstatus}" : "no exit status (likely force killed)")
raise Thor::CommandFailedError.new(message)
end
result
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment