Provide functionality to call application commands by calling PyBridge. ex: app('help') :param command: command line being run :param echo: If provided, this temporarily overrides the value of self.cmd_echo while the command runs. If True, output will be
(self, command: str, *, echo: bool | None = None)
| 95 | return attributes |
| 96 | |
| 97 | def __call__(self, command: str, *, echo: bool | None = None) -> CommandResult: |
| 98 | """Provide functionality to call application commands by calling PyBridge. |
| 99 | |
| 100 | ex: app('help') |
| 101 | :param command: command line being run |
| 102 | :param echo: If provided, this temporarily overrides the value of self.cmd_echo |
| 103 | while the command runs. If True, output will be echoed to _cmd2_app.stdout |
| 104 | and sys.stderr. (Defaults to None) |
| 105 | """ |
| 106 | if echo is None: |
| 107 | echo = self.cmd_echo |
| 108 | |
| 109 | # This will be used to capture _cmd2_app.stdout |
| 110 | copy_cmd_stdout = StdSim(cast(TextIO | StdSim, self._cmd2_app.stdout), echo=echo) |
| 111 | |
| 112 | # Pause the storing of stdout until onecmd_plus_hooks enables it |
| 113 | copy_cmd_stdout.pause_storage = True |
| 114 | |
| 115 | # This will be used to capture sys.stderr |
| 116 | copy_stderr = StdSim(sys.stderr, echo=echo) |
| 117 | |
| 118 | self._cmd2_app.last_result = None |
| 119 | |
| 120 | stop = False |
| 121 | try: |
| 122 | self._cmd2_app.stdout = cast(TextIO, copy_cmd_stdout) |
| 123 | |
| 124 | with redirect_stderr(cast(IO[str], copy_stderr)): |
| 125 | stop = self._cmd2_app.onecmd_plus_hooks( |
| 126 | command, |
| 127 | add_to_history=self._add_to_history, |
| 128 | py_bridge_call=True, |
| 129 | ) |
| 130 | finally: |
| 131 | with self._cmd2_app.sigint_protection: |
| 132 | self._cmd2_app.stdout = cast(TextIO, copy_cmd_stdout.inner_stream) |
| 133 | self.stop = stop or self.stop |
| 134 | |
| 135 | # Save the result |
| 136 | return CommandResult( |
| 137 | stdout=copy_cmd_stdout.getvalue(), |
| 138 | stderr=copy_stderr.getvalue(), |
| 139 | stop=stop, |
| 140 | data=self._cmd2_app.last_result, |
| 141 | ) |
nothing calls this directly
no test coverage detected