@@ -196,11 +196,8 @@ def _update_defaults(self, defaults):
196
196
val = strtobool (val )
197
197
except ValueError :
198
198
self .error (
199
- "#{0} is not a valid value. Valid true values"
200
- "are {1}, {2}, {3}, {4} and valid false values"
201
- "are {5}, {6}, {7}, {8}" .format (
202
- val , "true" , "yes" , "on" , 1 ,
203
- "false" , "no" , "off" , 0
199
+ self .invalid_config_error_message (
200
+ option .action , key , val
204
201
)
205
202
)
206
203
elif option .action == 'append' :
@@ -245,6 +242,18 @@ def get_default_values(self):
245
242
defaults [option .dest ] = option .check_value (opt_str , default )
246
243
return optparse .Values (defaults )
247
244
245
+ def invalid_config_error_message (self , action , key , val ):
246
+ """Returns a better error message when invalid configuration option
247
+ is provided."""
248
+ if action in ('store_true' , 'store_false' ):
249
+ return ("{0} is not a valid value for {1} option, "
250
+ "please specify a boolean value like yes/no, "
251
+ "true/false or 1/0 instead." ).format (val , key )
252
+
253
+ return ("{0} is not a valid value for {1} option, "
254
+ "please specify a numerical value like 1/0 "
255
+ "instead." ).format (val , key )
256
+
248
257
def error (self , msg ):
249
258
self .print_usage (sys .stderr )
250
259
self .exit (2 , "%s\n " % msg )
0 commit comments