Add a -q option to be silent on success

Change-Id: I5cd7f72694d525420a46e5ec2aca1b394bbf7b90
This commit is contained in:
Ned Batchelder 2017-01-14 20:01:59 -05:00 committed by briancurtin
parent 08be40a220
commit bcdaf5f788
2 changed files with 18 additions and 11 deletions

View File

@ -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.

View File

@ -176,6 +176,7 @@ def setup_logging(verbose):
def scan(cfg):
if not cfg.get('quiet'):
print("Scanning...")
files = collections.deque()
ignored_paths = cfg.get('ignore_path', [])
@ -200,6 +201,7 @@ def scan(cfg):
def validate(cfg, files):
if not cfg.get('quiet'):
print("Validating...")
error_counts = {}
ignoreables = frozenset(cfg.get('ignore', []))
@ -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,6 +362,7 @@ def main():
error_counts = validate(args, files)
total_errors = sum(six.itervalues(error_counts))
if not args.get('quiet'):
print("=" * 8)
print("Total files scanned = %s" % (files_selected))
print("Total files ignored = %s" % (files_ignored))
@ -367,6 +372,7 @@ def main():
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: