From f44d91f225e8accfa1bafda2cacb3b9e00daf855 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Mon, 8 Apr 2013 12:17:13 +0300 Subject: [PATCH] Add --warnings-exit-nonzero option. Forces exiting with code 2 when warnings present. Fixes: #347 --- bin/jsduck | 4 +++- lib/jsduck/app.rb | 8 ++++++++ lib/jsduck/logger.rb | 5 +++++ lib/jsduck/options.rb | 13 +++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/bin/jsduck b/bin/jsduck index 2f24bf31..98585df6 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 ec96ce34..96fe9ecc 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 d31f0356..a8898d36 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 e154520d..596c9757 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.", "", -- GitLab