MCPcopy
hub / github.com/fastapi/typer / invoke

Method invoke

typer/testing.py:275–342  ·  view source on GitHub ↗
(
        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,
    )

Source from the content-addressed store, hash-verified

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

Callers 9

test_raw_terminalFunction · 0.95
test_clirunner_getcharFunction · 0.95
test_clirunner_env_noneFunction · 0.95
test_promptFunction · 0.95
test_styleFunction · 0.95
test_winconsole_stdinFunction · 0.95
test_winconsole_stdoutFunction · 0.95
test_winconsole_stderrFunction · 0.95

Calls 7

isolationMethod · 0.95
get_default_prog_nameMethod · 0.95
ResultClass · 0.85
getvalueMethod · 0.80
mainMethod · 0.45
writeMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected