@@ -248,6 +248,20 @@ def add_subparser(command: str, text: str, **kwargs: Any) -> argparse.ArgumentPa
248248 metavar = "BASE_REF" ,
249249 help = "Git reference (commit, branch, tag) to check. Default: load current code." ,
250250 )
251+ check_options .add_argument (
252+ "--color" ,
253+ dest = "color" ,
254+ action = "store_true" ,
255+ default = None ,
256+ help = "Force enable colors in the output." ,
257+ )
258+ check_options .add_argument (
259+ "--no-color" ,
260+ dest = "color" ,
261+ action = "store_false" ,
262+ default = None ,
263+ help = "Force disable colors in the output." ,
264+ )
251265 check_options .add_argument ("-v" , "--verbose" , action = "store_true" , help = "Verbose output." )
252266 add_common_options (check_parser )
253267
@@ -343,6 +357,7 @@ def check(
343357 search_paths : Sequence [str | Path ] | None = None ,
344358 allow_inspection : bool = True ,
345359 verbose : bool = False ,
360+ color : bool | None = None ,
346361) -> int :
347362 """Load packages data and dump it as JSON.
348363
@@ -359,9 +374,6 @@ def check(
359374 Returns:
360375 `0` for success, `1` for failure.
361376 """
362- colorama .deinit ()
363- colorama .init ()
364-
365377 search_paths = list (search_paths ) if search_paths else []
366378
367379 try :
@@ -404,10 +416,14 @@ def check(
404416 allow_inspection = allow_inspection ,
405417 )
406418
407- style = ExplanationStyle .VERBOSE if verbose else ExplanationStyle .ONE_LINE
408419 breakages = list (find_breaking_changes (old_package , new_package ))
420+
421+ colorama .deinit ()
422+ colorama .init (strip = color if color is None else not color )
423+ style = ExplanationStyle .VERBOSE if verbose else ExplanationStyle .ONE_LINE
409424 for breakage in breakages :
410425 print (breakage .explain (style = style ), file = sys .stderr )
426+
411427 if breakages :
412428 return 1
413429 return 0
0 commit comments