Clarify filter error messages

This commit is contained in:
Garrett Holmstrom
2013-07-05 16:26:23 -07:00
parent 675cd646f6
commit 04600c0205

View File

@@ -127,18 +127,19 @@ class Filter(object):
ArgumentTypeError will result as well.
'''
if '=' not in argval:
msg = 'filter {0} must have format "NAME=VALUE"'.format(argval)
msg = "filter '{0}' must have format 'NAME=VALUE'".format(argval)
raise argparse.ArgumentTypeError(msg)
(name, value_str) = argval.split('=', 1)
try:
value = self.type(value_str)
except ValueError:
msg = 'filter {0} must have type {1}'.format(
value_str, self.type.__name__)
msg = "{0} filter value '{1}' must have type {2}".format(
name, value_str, self.type.__name__)
raise argparse.ArgumentTypeError(msg)
if self.choices and value not in self.choices:
msg = 'filter value {0} must match one of {1}'.format(
value, ', '.join([str(choice) for choice in self.choices]))
msg = "{0} filter value '{1}' must match one of {2}".format(
name, value,
', '.join([str(choice) for choice in self.choices]))
raise argparse.ArgumentTypeError(msg)
if value == '':
value = EMPTY