diff --git a/chkcrontab b/chkcrontab index 6952bf226afa9731cdbae46ba2d9e739f7202df9..1e5b3832e4b3644b568c57d90aa6112653e1ce37 100755 --- a/chkcrontab +++ b/chkcrontab @@ -29,6 +29,7 @@ __author__ = 'lyda@google.com (Kevin Lyda)' import sys import chkcrontab_lib as check +from optparse import OptionParser def main(argv): """main program.""" @@ -41,11 +42,23 @@ def main(argv): return check.check_crontab(argv[1], log, get_whitelisted_users(argv)) def get_whitelisted_users(argv): - if len(argv) > 2: - for arg in argv: - if '--whitelist' in arg: - return arg['--whitelist='.__len__():].split(',') - return None + """Gets the list of whitelisted users, if any. + + Args: + argv: The argument string supplied by the caller. + + Returns: + The list of whitelisted users. + """ + parser = OptionParser() + parser.add_option('-w', '--whitelist', dest='whitelisted_users', action='append', + help='A user to ignore when warning of unrecognized users This argument may be passed multiple times.') + (options, args) = parser.parse_args(argv) + + if options.whitelisted_users: + return options.whitelisted_users + else: + return None if __name__ == '__main__': sys.exit(main(sys.argv)) \ No newline at end of file