From bcdaf5f7883ad76339b21b4007cfcace63384cb4 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 14 Jan 2017 20:01:59 -0500 Subject: [PATCH] Add a -q option to be silent on success Change-Id: I5cd7f72694d525420a46e5ec2aca1b394bbf7b90 --- README.rst | 1 + doc8/main.py | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/README.rst b/README.rst index 71510b5..fb7d0ce 100644 --- a/README.rst +++ b/README.rst @@ -73,6 +73,7 @@ Command line usage -e extension, --extension extension check file extensions of the given type (default: .rst, .txt). + -q, --quiet only print violations -v, --verbose run in verbose mode. --version show the version and exit. diff --git a/doc8/main.py b/doc8/main.py index 4f2d4f5..fcf7c8b 100644 --- a/doc8/main.py +++ b/doc8/main.py @@ -176,7 +176,8 @@ def setup_logging(verbose): def scan(cfg): - print("Scanning...") + if not cfg.get('quiet'): + print("Scanning...") files = collections.deque() ignored_paths = cfg.get('ignore_path', []) files_ignored = 0 @@ -200,7 +201,8 @@ def scan(cfg): def validate(cfg, files): - print("Validating...") + if not cfg.get('quiet'): + print("Validating...") error_counts = {} ignoreables = frozenset(cfg.get('ignore', [])) ignore_targeted = cfg.get('ignore_path_errors', {}) @@ -325,6 +327,8 @@ def main(): help="check file extensions of the given type" " (default: %s)." % ", ".join(FILE_PATTERNS), default=list(FILE_PATTERNS)) + parser.add_argument("-q", "--quiet", action='store_true', + help="only print violations", default=False) parser.add_argument("-v", "--verbose", dest="verbose", action='store_true', help="run in verbose mode.", default=False) parser.add_argument("--version", dest="version", action='store_true', @@ -358,15 +362,17 @@ def main(): error_counts = validate(args, files) total_errors = sum(six.itervalues(error_counts)) - print("=" * 8) - print("Total files scanned = %s" % (files_selected)) - print("Total files ignored = %s" % (files_ignored)) - print("Total accumulated errors = %s" % (total_errors)) - if error_counts: - print("Detailed error counts:") - for check_name in sorted(six.iterkeys(error_counts)): - check_errors = error_counts[check_name] - print(" - %s = %s" % (check_name, check_errors)) + if not args.get('quiet'): + print("=" * 8) + print("Total files scanned = %s" % (files_selected)) + print("Total files ignored = %s" % (files_ignored)) + print("Total accumulated errors = %s" % (total_errors)) + if error_counts: + print("Detailed error counts:") + for check_name in sorted(six.iterkeys(error_counts)): + check_errors = error_counts[check_name] + print(" - %s = %s" % (check_name, check_errors)) + if total_errors: return 1 else: