1818from ._click .parser import _OptionParser
1919from ._click .shell_completion import CompletionItem
2020from ._typing import Literal
21+ from .exceptions import Abort , Exit
2122from .utils import parse_boolean_env_var
2223
2324MarkupMode = Literal ["markdown" , "rich" , None ]
@@ -165,13 +166,10 @@ def _main(
165166 rich_markup_mode : MarkupMode = DEFAULT_MARKUP_MODE ,
166167 ** extra : Any ,
167168) -> Any :
168- # Typer override, duplicated from _click.main() to handle custom rich exceptions
169- # Verify that the environment is configured correctly, or reject
170- # further execution to avoid a broken script.
169+ # Originally copied from _click.main(), adopted to handle custom rich exceptions etc
171170 if args is None :
172171 args = sys .argv [1 :]
173172
174- # Covered in Click tests
175173 if os .name == "nt" and windows_expand_args : # pragma: no cover
176174 args = _click .utils ._expand_args (args )
177175 else :
@@ -199,20 +197,18 @@ def _main(
199197 ctx .exit ()
200198 except EOFError as e :
201199 _click .echo (file = sys .stderr )
202- raise _click . exceptions . Abort () from e
200+ raise Abort () from e
203201 except KeyboardInterrupt as e :
204- raise _click . exceptions . Exit (130 ) from e
202+ raise Exit (130 ) from e
205203 except _click .exceptions .ClickException as e :
206204 if not standalone_mode :
207205 raise
208- # Typer override
209206 if HAS_RICH and rich_markup_mode is not None :
210207 from . import rich_utils
211208
212209 rich_utils .rich_format_error (e )
213210 else :
214211 e .show ()
215- # Typer override end
216212 sys .exit (e .exit_code )
217213 except OSError as e :
218214 if e .errno == errno .EPIPE :
@@ -221,7 +217,7 @@ def _main(
221217 sys .exit (1 )
222218 else :
223219 raise
224- except _click . exceptions . Exit as e :
220+ except Exit as e :
225221 if standalone_mode :
226222 sys .exit (e .exit_code )
227223 else :
@@ -234,17 +230,15 @@ def _main(
234230 # `ctx.exit(1)` and to `return 1`, the caller won't be able to
235231 # tell the difference between the two
236232 return e .exit_code
237- except _click . exceptions . Abort :
233+ except Abort :
238234 if not standalone_mode :
239235 raise
240- # Typer override
241236 if HAS_RICH and rich_markup_mode is not None :
242237 from . import rich_utils
243238
244239 rich_utils .rich_abort_error ()
245240 else :
246241 _click .echo (_ ("Aborted!" ), file = sys .stderr )
247- # Typer override end
248242 sys .exit (1 )
249243
250244
0 commit comments