MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / output_to

Method output_to

cmd2/argparse_utils.py:571–584  ·  view source on GitHub ↗

Context manager to temporarily set the output stream during argparse operations. This is helpful for directing output for functions like `parse_args()`, which default to `sys.stdout` and lack a `file` argument. :param file: the file stream to use for output

(self, file: IO[str] | None)

Source from the content-addressed store, hash-verified

569
570 @contextlib.contextmanager
571 def output_to(self, file: IO[str] | None) -> Iterator[None]:
572 """Context manager to temporarily set the output stream during argparse operations.
573
574 This is helpful for directing output for functions like `parse_args()`, which
575 default to `sys.stdout` and lack a `file` argument.
576
577 :param file: the file stream to use for output
578 """
579 previous = self._thread_locals.current_output_file
580 self._thread_locals.current_output_file = file
581 try:
582 yield
583 finally:
584 self._thread_locals.current_output_file = previous
585
586 def __init__(
587 self,

Callers 6

print_usageMethod · 0.95
print_helpMethod · 0.95
errorMethod · 0.95
cmd_wrapperFunction · 0.80

Calls

no outgoing calls