Reduce redundancy in get_level_by_argv with tryremove.
This commit is contained in:
parent
f1df7ef3f5
commit
414fc60f48
1 changed files with 12 additions and 10 deletions
|
@ -66,21 +66,23 @@ def get_level_by_argv(argv):
|
|||
'''
|
||||
argv = argv[:]
|
||||
|
||||
if '--loud' in argv:
|
||||
def tryremove(lst, item):
|
||||
try:
|
||||
lst.remove(item)
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
if tryremove(argv, '--loud'):
|
||||
level = LOUD
|
||||
argv.remove('--loud')
|
||||
elif '--debug' in argv:
|
||||
elif tryremove(argv, '--debug'):
|
||||
level = DEBUG
|
||||
argv.remove('--debug')
|
||||
elif '--warning' in argv:
|
||||
elif tryremove(argv, '--warning'):
|
||||
level = WARNING
|
||||
argv.remove('--warning')
|
||||
elif '--quiet' in argv:
|
||||
elif tryremove(argv, '--quiet'):
|
||||
level = ERROR
|
||||
argv.remove('--quiet')
|
||||
elif '--silent' in argv:
|
||||
elif tryremove(argv, '--silent'):
|
||||
level = SILENT
|
||||
argv.remove('--silent')
|
||||
else:
|
||||
level = INFO
|
||||
|
||||
|
|
Loading…
Reference in a new issue