Commit 2b25a8e7 authored by Kevin Lyda's avatar Kevin Lyda 💬
Browse files

Make the -q switch more effective.

parent 46f47dfa
......@@ -52,13 +52,9 @@ def main(argv):
dest='quiet', help='be quiet')
args = parser.parse_args()
log = check.LogCounter()
if args.version:
print('Version %s\n' % __version__)
return 0
if not args.quiet:
print('Checking correctness of %s' % args.crontab)
return check.check_crontab(args, log)
return check.check_crontab(args, check.LogCounter(args.quiet))
if __name__ == '__main__':
sys.exit(main(sys.argv))
......@@ -896,13 +896,14 @@ class LogCounter(object):
'HOURS_NOT_MINUTES',
'COMMENT'))
def __init__(self):
def __init__(self, quiet=False):
"""Inits LogCounter."""
self._error_count = 0
self._warn_count = 0
self._ignored = set()
self._line_errors = []
self._line_warns = []
self._quiet = quiet
def Ignore(self, msg_kind):
"""Start ignoring a category of message.
......@@ -957,6 +958,7 @@ class LogCounter(object):
Args:
message: The message to print as a warning.
"""
if not self._quiet:
print('W:', message)
self._warn_count += 1
......@@ -981,6 +983,7 @@ class LogCounter(object):
Args:
message: The message to print as a error.
"""
if not self._quiet:
print('E:', message)
self._error_count += 1
......@@ -1011,6 +1014,7 @@ class LogCounter(object):
spacer = ' ' * len('%d' % line_no)
line_error_fmt = 'e: %s %%s' % spacer
line_warn_fmt = 'w: %s %%s' % spacer
if not self._quiet:
if self._line_errors:
print('E: %d: %s' % (line_no, line))
else:
......@@ -1034,11 +1038,13 @@ class LogCounter(object):
"""
more_info = 'See http://goo.gl/7XS9q for more info.'
if self._error_count > 0:
if not self._quiet:
print('E: There were %d errors and %d warnings.'
% (self._error_count, self._warn_count))
print(more_info)
return 2
elif self._warn_count > 0:
if not self._quiet:
print('W: There were %d warnings.' % self._warn_count)
print(more_info)
return 1
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment