diff --git a/oa/core/hub.py b/oa/core/hub.py index 2453ffb..e14f6fe 100644 --- a/oa/core/hub.py +++ b/oa/core/hub.py @@ -28,7 +28,9 @@ def run(self): def put(self, part, value): """ Put a message on the wire. """ + _logger.debug(f"PUT Called... {part} <- {value}") if part in self.parts: + _logger.debug("Part specified... putting on the wire.") self.parts[part].wire_in.put(value) diff --git a/oa/modules/abilities/core.py b/oa/modules/abilities/core.py index 0e4edae..1cb949f 100644 --- a/oa/modules/abilities/core.py +++ b/oa/modules/abilities/core.py @@ -58,6 +58,7 @@ def get(part = None, timeout = .1): def put(part, value): """ Put a message on the wire. """ + _logger.debug(f"PUT Called... {part} <- {value}") oa.legacy.hub.parts[part].wire_in.put(value) def empty(part = None): diff --git a/oa/util/repl.py b/oa/util/repl.py index 062617e..65181c5 100644 --- a/oa/util/repl.py +++ b/oa/util/repl.py @@ -1,10 +1,16 @@ import logging +import re + + _logger = logging.getLogger(__name__) +regex_mind_command = re.compile(r'^(\S+):') -def command_loop(hub:object) -> None: +def command_loop(hub: object) -> None: """Responsible for maintaining command line interface for OA. Interfaces - textual commands with the hub. + textual commands with the hub. Commands are directed to the OA bus addressed + to the minds by default. Commands can be directed at modules specifically + using the syntax `: ` Args: hub (object): The current instance of hub passed over from oa.__main__.py @@ -18,13 +24,21 @@ def command_loop(hub:object) -> None: while not hub.finished.is_set(): cmd = input("OA> ") + _logger.debug("Raw CLI Command: {}".format(cmd)) if cmd in ['q', 'quit']: hub.finished.set() + break elif cmd in ['h', 'help', '?']: print("Help Stuff") - elif cmd.find(' ') > -1: - p, m = cmd.split(' ', 1) - _logger.debug("{} <- {}".format(p, m)) - hub.put(p, m) + continue + elif regex_mind_command.match(cmd): + # Dircted at a specific module. Extract the module and command. + # Remove initial whitespace if space was given after : + p, m = cmd.split(':', 1) + m = m.lstrip(' ') else: - print("Unrecognized command: {}".format(cmd)) + # Default to send the command to the minds. + p, m = "mind", cmd + + _logger.debug("{} <- {}".format(p, m)) + hub.put(p, m)