(
self,
app: Typer,
args: str | Sequence[str] | None = None,
input: bytes | str | None = None,
env: Mapping[str, str | None] | None = None,
catch_exceptions: bool = True,
color: bool = False,
**extra: Any,
)
| 273 | formatting.FORCED_WIDTH = old_forced_width |
| 274 | |
| 275 | def invoke( |
| 276 | self, |
| 277 | app: Typer, |
| 278 | args: str | Sequence[str] | None = None, |
| 279 | input: bytes | str | None = None, |
| 280 | env: Mapping[str, str | None] | None = None, |
| 281 | catch_exceptions: bool = True, |
| 282 | color: bool = False, |
| 283 | **extra: Any, |
| 284 | ) -> Result: |
| 285 | cli = _get_command(app) |
| 286 | exc_info = None |
| 287 | |
| 288 | with self.isolation(input=input, env=env, color=color) as outstreams: |
| 289 | return_value = None |
| 290 | exception: BaseException | None = None |
| 291 | exit_code = 0 |
| 292 | |
| 293 | if isinstance(args, str): |
| 294 | args = shlex.split(args) |
| 295 | |
| 296 | try: |
| 297 | prog_name = extra.pop("prog_name") |
| 298 | except KeyError: |
| 299 | prog_name = self.get_default_prog_name(cli) |
| 300 | |
| 301 | try: |
| 302 | return_value = cli.main(args=args or (), prog_name=prog_name, **extra) |
| 303 | except SystemExit as e: |
| 304 | exc_info = sys.exc_info() |
| 305 | e_code = cast("int | Any | None", e.code) |
| 306 | |
| 307 | if e_code is None: |
| 308 | e_code = 0 |
| 309 | |
| 310 | if e_code != 0: |
| 311 | exception = e |
| 312 | |
| 313 | if not isinstance(e_code, int): |
| 314 | sys.stdout.write(str(e_code)) |
| 315 | sys.stdout.write("\n") |
| 316 | e_code = 1 |
| 317 | |
| 318 | exit_code = e_code |
| 319 | |
| 320 | except Exception as e: |
| 321 | if not catch_exceptions: |
| 322 | raise |
| 323 | exception = e |
| 324 | exit_code = 1 |
| 325 | exc_info = sys.exc_info() |
| 326 | finally: |
| 327 | sys.stdout.flush() |
| 328 | sys.stderr.flush() |
| 329 | stdout = outstreams[0].getvalue() |
| 330 | stderr = outstreams[1].getvalue() |
| 331 | output = outstreams[2].getvalue() |
| 332 |
no test coverage detected