make error message function helper one
@@ -195,11 +195,11 @@ class ConfigOptionParser(CustomOptionParser):
try:
val = strtobool(val)
except ValueError:
- self.error(
- self.invalid_config_error_message(
+ error_msg = invalid_config_error_message(
option.action, key, val
)
- )
+ self.error(error_msg)
+
elif option.action == 'append':
val = val.split()
val = [self.check_default(option, key, v) for v in val]
@@ -242,7 +242,11 @@ class ConfigOptionParser(CustomOptionParser):
defaults[option.dest] = option.check_value(opt_str, default)
return optparse.Values(defaults)
- def invalid_config_error_message(self, action, key, val):
+ def error(self, msg):
+ self.print_usage(sys.stderr)
+ self.exit(2, "%s\n" % msg)
+
+def invalid_config_error_message(action, key, val):
"""Returns a better error message when invalid configuration option
is provided."""
if action in ('store_true', 'store_false'):
@@ -253,7 +257,3 @@ class ConfigOptionParser(CustomOptionParser):
return ("{0} is not a valid value for {1} option, "
"please specify a numerical value like 1/0 "
"instead.").format(val, key)
-
- def error(self, msg):
- self.print_usage(sys.stderr)
- self.exit(2, "%s\n" % msg)
