Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added --cron option. Works like silent, except if there is an error it

prints the full backtrace.
  • Loading branch information...
commit e7ae66cfd779803c22180810fb069455765e5618 1 parent 761aa74
@danlucraft authored
View
10 lib/rake/application.rb
@@ -144,13 +144,13 @@ def standard_exception_handling
def display_error_message(ex)
$stderr.puts "#{name} aborted!"
$stderr.puts ex.message
- if options.trace
+ if options.trace or options.cron
$stderr.puts ex.backtrace.join("\n")
else
$stderr.puts rakefile_location(ex.backtrace)
end
$stderr.puts "Tasks: #{ex.chain}" if has_chain?(ex)
- $stderr.puts "(See full trace by running task with --trace)" unless options.trace
+ $stderr.puts "(See full trace by running task with --trace)" unless options.trace or options.cron
end
# Warn about deprecated usage.
@@ -388,6 +388,12 @@ def standard_rake_options
Rake.verbose(true)
}
],
+ ['--cron', '-c', "Like --silent, but full backtraces are printed on errors (useful for cronjobs)",
+ lambda { |value|
+ options.cron = true
+ options.silent = true
+ }
+ ],
['--verbose', '-v', "Log message to standard output.",
lambda { |value| Rake.verbose(true) }
],
View
20 test/test_rake_application.rb
@@ -338,7 +338,25 @@ def test_bad_run_with_trace
rake_capture_io(out, err) { @app.run }
}
err.rewind
- refute_match(/See full trace/, err.read)
+ err_s = err.read
+ refute_match(/See full trace/, err_s)
+ assert_match(/application.rb/, err_s)
+ ensure
+ ARGV.clear
+ end
+
+ def test_bad_run_with_cron
+ @app.intern(Rake::Task, "default").enhance { fail }
+ ARGV.clear
+ ARGV << '-f' << '-s' << '-c'
+ out, err = StringIO.new, StringIO.new
+ assert_raises(SystemExit) {
+ rake_capture_io(out, err) { @app.run }
+ }
+ err.rewind
+ err_s = err.read
+ refute_match(/See full trace/, err_s)
+ assert_match(/application.rb/, err_s)
ensure
ARGV.clear
end
View
9 test/test_rake_application_options.rb
@@ -234,6 +234,15 @@ def test_trace
end
end
+ def test_cron
+ in_environment do
+ flags('--cron', '-c') do |opts|
+ assert opts.cron
+ assert opts.silent
+ end
+ end
+ end
+
def test_trace_rules
in_environment do
flags('--rules') do |opts|
Please sign in to comment.
Something went wrong with that request. Please try again.