@@ -507,6 +507,7 @@ def parse_options(
507507 "--interactive" ,
508508 action = "store" ,
509509 type = int ,
510+ choices = (0 , 1 , 2 , 3 ),
510511 default = 0 ,
511512 help = "set interactive mode when writing changes:\n "
512513 "- 0: no interactivity.\n "
@@ -520,6 +521,7 @@ def parse_options(
520521 "--quiet-level" ,
521522 action = "store" ,
522523 type = int ,
524+ choices = range (0 , 64 ),
523525 default = 34 ,
524526 help = "bitmask that allows suppressing messages:\n "
525527 "- 0: print all messages.\n "
@@ -1248,15 +1250,36 @@ def main(*args: str) -> int:
12481250 )
12491251 parser .print_help ()
12501252 return EX_USAGE
1251- context_both = max (0 , options .context )
1253+ if options .context < 0 :
1254+ print (
1255+ "ERROR: --context/-C accepts positive values only" ,
1256+ file = sys .stderr ,
1257+ )
1258+ context_both = options .context
12521259 context = (context_both , context_both )
1253- elif (options .before_context is not None ) or (options .after_context is not None ):
1254- context_before = 0
1255- context_after = 0
1260+ else :
12561261 if options .before_context is not None :
1257- context_before = max (0 , options .before_context )
1262+ if options .before_context < 0 :
1263+ print (
1264+ "ERROR: --context-before/-B accepts only positive values" ,
1265+ file = sys .stderr ,
1266+ )
1267+ parser .print_help ()
1268+ return EX_USAGE
1269+ context_before = options .before_context
1270+ else :
1271+ context_before = 0
12581272 if options .after_context is not None :
1259- context_after = max (0 , options .after_context )
1273+ if options .after_context < 0 :
1274+ print (
1275+ "ERROR: --context-after/-A accepts only positive values" ,
1276+ file = sys .stderr ,
1277+ )
1278+ parser .print_help ()
1279+ return EX_USAGE
1280+ context_after = options .after_context
1281+ else :
1282+ context_after = 0
12601283 context = (context_before , context_after )
12611284
12621285 exclude_lines : Set [str ] = set ()
0 commit comments