lib/travis/cli/command.rb in travis-1.4.0 vs lib/travis/cli/command.rb in travis-1.5.0
- old
+ new
@@ -56,10 +56,11 @@
attr_accessor :arguments, :config, :force_interactive, :formatter
attr_reader :input, :output
def initialize(options = {})
+ @on_signal = []
@formatter = Travis::Tools::Formatter.new
self.output = $stdout
self.input = $stdin
options.each do |key, value|
public_send("#{key}=", value) if respond_to? "#{key}="
@@ -122,10 +123,11 @@
return if RUBY_VERSION > '1.9.2' or skip_version_check?
warn "Your Ruby version is outdated, please consider upgrading, as we will drop support for #{RUBY_VERSION} soon!"
end
def execute
+ setup_trap
check_ruby
check_arity(method(:run), *arguments)
load_config
check_version
setup
@@ -171,10 +173,23 @@
write_to($stderr) do
say color("** #{line}", :debug)
end
end
+ def on_signal(&block)
+ @on_signal << block
+ end
+
private
+
+ def setup_trap
+ [:INT, :TERM].each do |signal|
+ trap signal do
+ @on_signal.each { |c| c.call }
+ exit 1
+ end
+ end
+ end
def format(data, format = nil, style = nil)
style ||= :important
data = format % color(data, style) if format and interactive?
data = data.gsub(/<\[\[/, '<%=').gsub(/\]\]>/, '%>')