Validation of logger names passed to --logfilter

This commit is contained in:
knaggita 2016-08-24 15:15:20 +03:00
parent 6b4f719897
commit 848af2e294

View File

@ -23,6 +23,7 @@ import sys
import json
import qutebrowser
from qutebrowser.utils import log
try:
from qutebrowser.misc.checkpyver import check_python_version
except ImportError:
@ -81,7 +82,7 @@ def get_argparser():
help="Set loglevel", default='info',
choices=['critical', 'error', 'warning', 'info',
'debug', 'vdebug'])
debug.add_argument('--logfilter',
debug.add_argument('--logfilter', type=logfilter_error,
help="Comma-separated list of things to be logged "
"to the debug log on stdout.")
debug.add_argument('--loglines',
@ -139,6 +140,14 @@ def get_argparser():
return parser
def logfilter_error(logfilter):
if set(logfilter.split(',')).issubset(log.LOGGER_NAMES)==False:
raise argparse.ArgumentTypeError("filters: Invalid value {} - expected one "
"of: {}".format(logfilter,
', '.join(log.LOGGER_NAMES)))
return logfilter
def main():
parser = get_argparser()
if sys.platform == 'darwin' and getattr(sys, 'frozen', False):