diff --git a/CHANGELOG.md b/CHANGELOG.md index ad1a2e13..5db7be7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,12 @@ ### New features +* [#27](https://github.com/mmozuras/pronto/issues/27): '--exit-code' option for 'pronto run'. Pronto exits with non-zero code if there were any warnings/errors. + ### Changes * [#29](https://github.com/mmozuras/pronto/issues/29): Be compatible and depend on rugged '0.21.0'. -* Performance improvement - use Rugged::Blame instead of one provided by Grit. -* Performance improvement - cache comments retrieved from GitHub. +* Performance improvement: use Rugged::Blame instead of one provided by Grit. +* Performance improvement: cache comments retrieved from GitHub. ### Bugs fixed diff --git a/lib/pronto.rb b/lib/pronto.rb index 683486c7..16db5678 100644 --- a/lib/pronto.rb +++ b/lib/pronto.rb @@ -29,7 +29,9 @@ def self.run(commit = 'master', repo_path = '.', formatter = nil) result = run_all_runners(patches) formatter ||= default_formatter - formatter.format(result, repo) + puts formatter.format(result, repo) + + result end def self.gem_names diff --git a/lib/pronto/cli.rb b/lib/pronto/cli.rb index 2a42be93..a839d8d4 100644 --- a/lib/pronto/cli.rb +++ b/lib/pronto/cli.rb @@ -14,6 +14,10 @@ def is_thor_reserved_word?(word, type) desc 'run', 'Run Pronto' + method_option :'exit-code', + type: :boolean, + banner: 'Exits with non-zero code if there were any warnings/errors.' + method_option :commit, type: :string, default: 'master', @@ -39,7 +43,8 @@ def run end formatter = ::Pronto::Formatter.get(options[:formatter]) - puts ::Pronto.run(options[:commit], '.', formatter) + messages = ::Pronto.run(options[:commit], '.', formatter) + exit(messages.count) if options[:'exit-code'] rescue Rugged::RepositoryError puts '"pronto" should be run from a git repository' end