Browse Source

Add a -q option to be silent on success

Change-Id: I5cd7f72694d525420a46e5ec2aca1b394bbf7b90
Ned Batchelder 2 years ago
parent
commit
bcdaf5f788
2 changed files with 18 additions and 11 deletions
  1. 1
    0
      README.rst
  2. 17
    11
      doc8/main.py

+ 1
- 0
README.rst View File

@@ -73,6 +73,7 @@ Command line usage
73 73
       -e extension, --extension extension
74 74
                             check file extensions of the given type (default:
75 75
                             .rst, .txt).
76
+      -q, --quiet           only print violations
76 77
       -v, --verbose         run in verbose mode.
77 78
       --version             show the version and exit.
78 79
 

+ 17
- 11
doc8/main.py View File

@@ -176,7 +176,8 @@ def setup_logging(verbose):
176 176
 
177 177
 
178 178
 def scan(cfg):
179
-    print("Scanning...")
179
+    if not cfg.get('quiet'):
180
+        print("Scanning...")
180 181
     files = collections.deque()
181 182
     ignored_paths = cfg.get('ignore_path', [])
182 183
     files_ignored = 0
@@ -200,7 +201,8 @@ def scan(cfg):
200 201
 
201 202
 
202 203
 def validate(cfg, files):
203
-    print("Validating...")
204
+    if not cfg.get('quiet'):
205
+        print("Validating...")
204 206
     error_counts = {}
205 207
     ignoreables = frozenset(cfg.get('ignore', []))
206 208
     ignore_targeted = cfg.get('ignore_path_errors', {})
@@ -325,6 +327,8 @@ def main():
325 327
                         help="check file extensions of the given type"
326 328
                              " (default: %s)." % ", ".join(FILE_PATTERNS),
327 329
                         default=list(FILE_PATTERNS))
330
+    parser.add_argument("-q", "--quiet", action='store_true',
331
+                        help="only print violations", default=False)
328 332
     parser.add_argument("-v", "--verbose", dest="verbose", action='store_true',
329 333
                         help="run in verbose mode.", default=False)
330 334
     parser.add_argument("--version", dest="version", action='store_true',
@@ -358,15 +362,17 @@ def main():
358 362
     error_counts = validate(args, files)
359 363
     total_errors = sum(six.itervalues(error_counts))
360 364
 
361
-    print("=" * 8)
362
-    print("Total files scanned = %s" % (files_selected))
363
-    print("Total files ignored = %s" % (files_ignored))
364
-    print("Total accumulated errors = %s" % (total_errors))
365
-    if error_counts:
366
-        print("Detailed error counts:")
367
-        for check_name in sorted(six.iterkeys(error_counts)):
368
-            check_errors = error_counts[check_name]
369
-            print("    - %s = %s" % (check_name, check_errors))
365
+    if not args.get('quiet'):
366
+        print("=" * 8)
367
+        print("Total files scanned = %s" % (files_selected))
368
+        print("Total files ignored = %s" % (files_ignored))
369
+        print("Total accumulated errors = %s" % (total_errors))
370
+        if error_counts:
371
+            print("Detailed error counts:")
372
+            for check_name in sorted(six.iterkeys(error_counts)):
373
+                check_errors = error_counts[check_name]
374
+                print("    - %s = %s" % (check_name, check_errors))
375
+
370 376
     if total_errors:
371 377
         return 1
372 378
     else:

Loading…
Cancel
Save