| 310 | return matching_commands, first_word, rest_inp |
| 311 | |
| 312 | def run(self, inp): |
| 313 | if inp.startswith("!"): |
| 314 | self.coder.event("command_run") |
| 315 | return self.do_run("run", inp[1:]) |
| 316 | |
| 317 | res = self.matching_commands(inp) |
| 318 | if res is None: |
| 319 | return |
| 320 | matching_commands, first_word, rest_inp = res |
| 321 | if len(matching_commands) == 1: |
| 322 | command = matching_commands[0][1:] |
| 323 | self.coder.event(f"command_{command}") |
| 324 | return self.do_run(command, rest_inp) |
| 325 | elif first_word in matching_commands: |
| 326 | command = first_word[1:] |
| 327 | self.coder.event(f"command_{command}") |
| 328 | return self.do_run(command, rest_inp) |
| 329 | elif len(matching_commands) > 1: |
| 330 | self.io.tool_error(f"Ambiguous command: {', '.join(matching_commands)}") |
| 331 | else: |
| 332 | self.io.tool_error(f"Invalid command: {first_word}") |
| 333 | |
| 334 | # any method called cmd_xxx becomes a command automatically. |
| 335 | # each one must take an args param. |