2222from ggshield .cmd .status import status_cmd
2323from ggshield .cmd .utils .common_options import add_common_options
2424from ggshield .cmd .utils .context_obj import ContextObj
25- from ggshield .cmd .utils .debug_logs import disable_logs , setup_debug_logs
26- from ggshield .core import check_updates
25+ from ggshield .cmd .utils .debug import setup_debug_mode
26+ from ggshield .core import check_updates , ui
2727from ggshield .core .cache import Cache
2828from ggshield .core .config import Config
2929from ggshield .core .env_utils import load_dot_env
3030from ggshield .core .errors import ExitCode
31- from ggshield .core .text_utils import display_warning
32- from ggshield .core .ui .plain_text .plain_text_ggshield_ui import PlainTextGGShieldUI
33- from ggshield .core .ui .rich .rich_ggshield_ui import RichGGShieldUI
31+ from ggshield .core .ui import log_utils
32+ from ggshield .core .ui .rich import RichGGShieldUI
3433from ggshield .utils .click import RealPath
3534from ggshield .utils .os import getenv_bool
3635
@@ -66,10 +65,6 @@ def config_path_callback(
6665 if not ctx .obj :
6766 ctx .obj = ContextObj ()
6867 ctx .obj .cache = Cache ()
69- if sys .stderr .isatty ():
70- ctx .obj .ui = RichGGShieldUI ()
71- else :
72- ctx .obj .ui = PlainTextGGShieldUI ()
7368
7469 ctx .obj .config = Config (value )
7570 return value
@@ -112,8 +107,8 @@ def cli(
112107 _set_color (ctx )
113108
114109 if config .user_config .debug :
115- # if `debug` is set in the configuration file, then setup logs now.
116- setup_debug_logs ( filename = None )
110+ # if `debug` is set in the configuration file, then setup debug mode now.
111+ setup_debug_mode ( )
117112
118113
119114def _set_color (ctx : click .Context ):
@@ -144,7 +139,7 @@ def _set_color(ctx: click.Context):
144139
145140def _display_deprecation_message (cfg : Config ) -> None :
146141 for message in cfg .user_config .deprecation_messages :
147- display_warning (message )
142+ ui . display_warning (message )
148143
149144
150145def _check_for_updates (check_for_updates : bool ) -> None :
@@ -154,7 +149,7 @@ def _check_for_updates(check_for_updates: bool) -> None:
154149 if check_for_updates and "PYTEST_CURRENT_TEST" not in os .environ :
155150 latest_version = check_updates .check_for_updates ()
156151 if latest_version :
157- display_warning (
152+ ui . display_warning (
158153 f"A new version of ggshield (v{ latest_version } ) has been released "
159154 f"(https://github.com/GitGuardian/ggshield)."
160155 )
@@ -185,7 +180,10 @@ def main(args: Optional[List[str]] = None) -> Any:
185180 # See https://pyinstaller.org/en/latest/common-issues-and-pitfalls.html#multi-processing
186181 multiprocessing .freeze_support ()
187182
188- disable_logs ()
183+ log_utils .disable_logs ()
184+ if sys .stderr .isatty ():
185+ ui .set_ui (RichGGShieldUI ())
186+
189187 show_crash_log = getenv_bool ("GITGUARDIAN_CRASH_LOG" )
190188 return cli .main (args , prog_name = "ggshield" , standalone_mode = not show_crash_log )
191189
0 commit comments