Created
June 4, 2013 21:52
-
-
Save ktheory/5709936 to your computer and use it in GitHub Desktop.
Monkeypatch for Thor `run_or_die` action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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