lib/travis/cli/command.rb in travis-1.5.9.travis.358.4 vs lib/travis/cli/command.rb in travis-1.5.9.travis.360.4
- old
+ new
@@ -52,12 +52,12 @@
def self.abstract
@@abstract << self
end
- def self.skip(name)
- define_method(name) {}
+ def self.skip(*names)
+ names.each { |n| define_method(n) {} }
end
def self.description(description = nil)
@description = description if description
@description ||= ""
@@ -155,16 +155,19 @@
load_config
check_version
check_completion
setup
run(*arguments)
+ clear_error
store_config
rescue StandardError => e
raise(e) if explode?
message = e.message
- message += " - need to run `travis login` again?" if Travis::Client::Error === e and message == 'access denied'
- error message
+ message += " - try running #{command("login#{endpoint_option}")}" if Travis::Client::Error === e and message == 'access denied'
+ message += color("\nfor a full error report, run #{command("report#{endpoint_option}")}", :error) if interactive?
+ store_error(e)
+ error(message)
end
def command_name
self.class.command_name
end
@@ -210,10 +213,20 @@
@on_signal << block
end
private
+ def store_error(exception)
+ message = "An error occurred running `travis %s%s`:\n %p: %s\n" % [command_name, endpoint_option, exception.class, exception.message]
+ exception.backtrace.each { |l| message << " from #{l}\n" }
+ save_file("error.log", message)
+ end
+
+ def clear_error
+ delete_file("error.log")
+ end
+
def setup_trap
[:INT, :TERM].each do |signal|
trap signal do
@on_signal.each { |c| c.call }
exit 1
@@ -276,10 +289,15 @@
def load_file(name, default = nil)
path = config_path(name)
File.exist?(path) ? File.read(path) : default
end
+ def delete_file(name)
+ path = config_path(name)
+ File.delete(path) if File.exist?(path)
+ end
+
def save_file(name, content)
File.write(config_path(name), content.to_s)
end
def load_config
@@ -302,9 +320,13 @@
def wrong_args(quantity)
error "too #{quantity} arguments" do
say help
end
+ end
+
+ def endpoint_option
+ ""
end
end
end
end