Dispatch user command. Args: command: (str) Command to dispatch. Returns: An exit token object. None value means that the UI loop should not exit. A non-None value means the UI loop should exit.
(self, command)
| 82 | return self._input(self.CLI_PROMPT).strip() |
| 83 | |
| 84 | def _dispatch_command(self, command): |
| 85 | """Dispatch user command. |
| 86 | |
| 87 | Args: |
| 88 | command: (str) Command to dispatch. |
| 89 | |
| 90 | Returns: |
| 91 | An exit token object. None value means that the UI loop should not exit. |
| 92 | A non-None value means the UI loop should exit. |
| 93 | """ |
| 94 | |
| 95 | if command in self.CLI_EXIT_COMMANDS: |
| 96 | # Explicit user command-triggered exit: EXPLICIT_USER_EXIT as the exit |
| 97 | # token. |
| 98 | return debugger_cli_common.EXPLICIT_USER_EXIT |
| 99 | |
| 100 | try: |
| 101 | prefix, args, output_file_path = self._parse_command(command) |
| 102 | except SyntaxError as e: |
| 103 | print(str(e)) |
| 104 | return |
| 105 | |
| 106 | if self._command_handler_registry.is_registered(prefix): |
| 107 | try: |
| 108 | screen_output = self._command_handler_registry.dispatch_command( |
| 109 | prefix, args, screen_info=None) |
| 110 | except debugger_cli_common.CommandLineExit as e: |
| 111 | return e.exit_token |
| 112 | else: |
| 113 | screen_output = debugger_cli_common.RichTextLines([ |
| 114 | self.ERROR_MESSAGE_PREFIX + "Invalid command prefix \"%s\"" % prefix |
| 115 | ]) |
| 116 | |
| 117 | self._display_output(screen_output) |
| 118 | if output_file_path: |
| 119 | try: |
| 120 | screen_output.write_to_file(output_file_path) |
| 121 | print("Wrote output to %s" % output_file_path) |
| 122 | except Exception: # pylint: disable=broad-except |
| 123 | print("Failed to write output to %s" % output_file_path) |
| 124 | |
| 125 | def _display_output(self, screen_output): |
| 126 | for line in screen_output.lines: |
no test coverage detected