summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2017-01-14 20:01:59 -0500
committerbriancurtin <brian.curtin@rackspace.com>2017-01-14 20:01:59 -0500
commitbcdaf5f7883ad76339b21b4007cfcace63384cb4 (patch)
treecc3cb64dd42874321364231c51b59d7ae19281a2
parent08be40a2200d7d6a5e6ecd03db7f7c923727b8b1 (diff)
Add a -q option to be silent on success
Notes
Notes (review): Code-Review+1: Doug Hellmann <doug@doughellmann.com> Code-Review+2: Joshua Harlow <jxharlow@godaddy.com> Workflow+1: Joshua Harlow <jxharlow@godaddy.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Tue, 21 Mar 2017 19:48:06 +0000 Reviewed-on: https://review.openstack.org/420374 Project: openstack/doc8 Branch: refs/heads/master
-rw-r--r--README.rst1
-rw-r--r--doc8/main.py28
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
73 -e extension, --extension extension 73 -e extension, --extension extension
74 check file extensions of the given type (default: 74 check file extensions of the given type (default:
75 .rst, .txt). 75 .rst, .txt).
76 -q, --quiet only print violations
76 -v, --verbose run in verbose mode. 77 -v, --verbose run in verbose mode.
77 --version show the version and exit. 78 --version show the version and exit.
78 79
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):
176 176
177 177
178def scan(cfg): 178def scan(cfg):
179 print("Scanning...") 179 if not cfg.get('quiet'):
180 print("Scanning...")
180 files = collections.deque() 181 files = collections.deque()
181 ignored_paths = cfg.get('ignore_path', []) 182 ignored_paths = cfg.get('ignore_path', [])
182 files_ignored = 0 183 files_ignored = 0
@@ -200,7 +201,8 @@ def scan(cfg):
200 201
201 202
202def validate(cfg, files): 203def validate(cfg, files):
203 print("Validating...") 204 if not cfg.get('quiet'):
205 print("Validating...")
204 error_counts = {} 206 error_counts = {}
205 ignoreables = frozenset(cfg.get('ignore', [])) 207 ignoreables = frozenset(cfg.get('ignore', []))
206 ignore_targeted = cfg.get('ignore_path_errors', {}) 208 ignore_targeted = cfg.get('ignore_path_errors', {})
@@ -325,6 +327,8 @@ def main():
325 help="check file extensions of the given type" 327 help="check file extensions of the given type"
326 " (default: %s)." % ", ".join(FILE_PATTERNS), 328 " (default: %s)." % ", ".join(FILE_PATTERNS),
327 default=list(FILE_PATTERNS)) 329 default=list(FILE_PATTERNS))
330 parser.add_argument("-q", "--quiet", action='store_true',
331 help="only print violations", default=False)
328 parser.add_argument("-v", "--verbose", dest="verbose", action='store_true', 332 parser.add_argument("-v", "--verbose", dest="verbose", action='store_true',
329 help="run in verbose mode.", default=False) 333 help="run in verbose mode.", default=False)
330 parser.add_argument("--version", dest="version", action='store_true', 334 parser.add_argument("--version", dest="version", action='store_true',
@@ -358,15 +362,17 @@ def main():
358 error_counts = validate(args, files) 362 error_counts = validate(args, files)
359 total_errors = sum(six.itervalues(error_counts)) 363 total_errors = sum(six.itervalues(error_counts))
360 364
361 print("=" * 8) 365 if not args.get('quiet'):
362 print("Total files scanned = %s" % (files_selected)) 366 print("=" * 8)
363 print("Total files ignored = %s" % (files_ignored)) 367 print("Total files scanned = %s" % (files_selected))
364 print("Total accumulated errors = %s" % (total_errors)) 368 print("Total files ignored = %s" % (files_ignored))
365 if error_counts: 369 print("Total accumulated errors = %s" % (total_errors))
366 print("Detailed error counts:") 370 if error_counts:
367 for check_name in sorted(six.iterkeys(error_counts)): 371 print("Detailed error counts:")
368 check_errors = error_counts[check_name] 372 for check_name in sorted(six.iterkeys(error_counts)):
369 print(" - %s = %s" % (check_name, check_errors)) 373 check_errors = error_counts[check_name]
374 print(" - %s = %s" % (check_name, check_errors))
375
370 if total_errors: 376 if total_errors:
371 return 1 377 return 1
372 else: 378 else: