diff --git a/bin/jsduck b/bin/jsduck index 2f24bf3100977cb2834961b6247944277c93c234..98585df64bbd03f4d447d918607b1dd16bed67ba 100755 --- a/bin/jsduck +++ b/bin/jsduck @@ -22,4 +22,6 @@ require 'jsduck/options' opts = JsDuck::Options.new opts.parse!(ARGV) -JsDuck::App.new(opts).run +exit_code = JsDuck::App.new(opts).run + +exit exit_code diff --git a/lib/jsduck/app.rb b/lib/jsduck/app.rb index ec96ce3402909af6b705f1cb031473c95d20e93c..96fe9eccb5e711258c55e3f5508143237701dd76 100644 --- a/lib/jsduck/app.rb +++ b/lib/jsduck/app.rb @@ -3,6 +3,7 @@ require 'jsduck/assets' require 'jsduck/meta_tag_registry' require 'jsduck/export_writer' require 'jsduck/web_writer' +require 'jsduck/logger' module JsDuck @@ -14,6 +15,7 @@ module JsDuck end # Main App logic. + # Returns application exit code. def run parse @@ -24,6 +26,12 @@ module JsDuck else generate_web_page end + + if @opts.warnings_exit_nonzero && Logger.warnings_logged? + return 2 + else + return 0 + end end private diff --git a/lib/jsduck/logger.rb b/lib/jsduck/logger.rb index d31f0356fa76f5335fa9ddd020e532df34834008..a8898d3678ae2e8a4d3fdf3d3b3477467bd34e49 100644 --- a/lib/jsduck/logger.rb +++ b/lib/jsduck/logger.rb @@ -140,6 +140,11 @@ module JsDuck $stderr.puts error.backtrace end + # True when at least one warning was logged. + def warnings_logged? + @shown_warnings.length > 0 + end + private COLORS = { diff --git a/lib/jsduck/options.rb b/lib/jsduck/options.rb index e154520daca93c2ab3e535fa8e3c35cb60588a71..596c975710ff831e45476c2364487a715245daf3 100644 --- a/lib/jsduck/options.rb +++ b/lib/jsduck/options.rb @@ -43,6 +43,7 @@ module JsDuck attr_accessor :ignore_html # Debugging + attr_accessor :warnings_exit_nonzero attr_accessor :template_dir attr_accessor :template_links attr_accessor :extjs_path @@ -122,6 +123,7 @@ module JsDuck @ignore_html = {} # Debugging + @warnings_exit_nonzero = false @root_dir = File.dirname(File.dirname(File.dirname(__FILE__))) @template_dir = @root_dir + "/template-min" @template_links = false @@ -609,6 +611,17 @@ module JsDuck end end + opts.on('--warnings-exit-nonzero', + "Exits with non-zero exit code on warnings.", + "", + "By default JSDuck only exits with non-zero exit code", + "when a fatal error is encountered (code 1).", + "", + "With this option the exit code will be 2 when any warning", + "gets printed.") do + @warnings_exit_nonzero = true + end + opts.on('--[no-]color', "Turn on/off colorized terminal output.", "",