@@ -65,10 +65,6 @@ def choices(self, val):
65
65
class CLIArgParser (argparse .ArgumentParser ):
66
66
Formatter = argparse .RawTextHelpFormatter
67
67
68
- # When displaying invalid choice error messages,
69
- # this controls how many options to show per line.
70
- ChoicesPerLine = 2
71
-
72
68
def _check_value (self , action , value ):
73
69
"""
74
70
It's probably not a great idea to override a "hidden" method
@@ -77,15 +73,10 @@ def _check_value(self, action, value):
77
73
"""
78
74
# converted value must be one of the choices (if specified)
79
75
if action .choices is not None and value not in action .choices :
80
- msg = ['Invalid choice, valid choices are:\n ' ]
81
- for i in range (len (action .choices ))[:: self .ChoicesPerLine ]:
82
- current = []
83
- for choice in action .choices [i : i + self .ChoicesPerLine ]:
84
- current .append ('%-40s' % choice )
85
- msg .append (' | ' .join (current ))
76
+ msg = [f"Found invalid choice '{ value } '\n " ]
86
77
possible = get_close_matches (value , action .choices , cutoff = 0.8 )
87
78
if possible :
88
- extra = ['\n \n Invalid choice: %r, maybe you meant:\n ' % value ]
79
+ extra = ['Maybe you meant:\n ' ]
89
80
for word in possible :
90
81
extra .append (' * %s' % word )
91
82
msg .extend (extra )
@@ -126,8 +117,8 @@ def error(self, message):
126
117
should raise an exception.
127
118
"""
128
119
usage_message = self .format_usage ()
129
- error_message = f'{ self .prog } : error: { message } \n '
130
- raise ArgParseException (f'{ usage_message } \n { error_message } ' )
120
+ error_message = f'{ self .prog } : error: { message } '
121
+ raise ArgParseException (f'{ error_message } \n \n { usage_message } ' )
131
122
132
123
133
124
class MainArgParser (CLIArgParser ):
0 commit comments