@@ -1238,26 +1238,49 @@ def main(*args: str) -> int:
12381238
12391239 summary = Summary () if options .summary else None
12401240
1241- context = None
1242- if options .context is not None :
1243- if (options .before_context is not None ) or (options .after_context is not None ):
1241+ if (options .before_context is not None ) or (options .after_context is not None ):
1242+ if options .context is not None :
12441243 print (
12451244 "ERROR: --context/-C cannot be used together with "
12461245 "--context-before/-B or --context-after/-A" ,
12471246 file = sys .stderr ,
12481247 )
12491248 parser .print_help ()
12501249 return EX_USAGE
1251- context_both = max (0 , options .context )
1252- 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
12561250 if options .before_context is not None :
1257- context_before = max (0 , options .before_context )
1251+ if options .before_context < 0 :
1252+ print (
1253+ "ERROR: --context-before/-B accepts only positive values" ,
1254+ file = sys .stderr ,
1255+ )
1256+ parser .print_help ()
1257+ return EX_USAGE
1258+ context_before = options .before_context
1259+ else :
1260+ context_before = 0
12581261 if options .after_context is not None :
1259- context_after = max (0 , options .after_context )
1262+ if options .after_context < 0 :
1263+ print (
1264+ "ERROR: --context-after/-A accepts only positive values" ,
1265+ file = sys .stderr ,
1266+ )
1267+ parser .print_help ()
1268+ return EX_USAGE
1269+ context_after = options .after_context
1270+ else :
1271+ context_after = 0
12601272 context = (context_before , context_after )
1273+ elif options .context is not None :
1274+ if options .context < 0 :
1275+ print (
1276+ "ERROR: --context/-C accepts positive values only" ,
1277+ file = sys .stderr ,
1278+ )
1279+ parser .print_help ()
1280+ return EX_USAGE
1281+ context = (options .context , options .context )
1282+ else :
1283+ context = None
12611284
12621285 exclude_lines : Set [str ] = set ()
12631286 if options .exclude_file :
0 commit comments