From d06d8a609fd5ba74dd7582777aacc51f4bd7d3a2 Mon Sep 17 00:00:00 2001 From: k-boikov <64261260+k-boikov@users.noreply.github.com> Date: Mon, 15 May 2023 21:41:11 +0300 Subject: [PATCH] Fix commands with same name overwriting (#4226) --- autogpt/commands/command.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/autogpt/commands/command.py b/autogpt/commands/command.py index 22ebace5a..174a691c5 100644 --- a/autogpt/commands/command.py +++ b/autogpt/commands/command.py @@ -3,6 +3,8 @@ import importlib import inspect from typing import Any, Callable, Optional +from autogpt.logs import logger + # Unique identifier for auto-gpt commands AUTO_GPT_COMMAND_IDENTIFIER = "auto_gpt_command" @@ -59,6 +61,10 @@ class CommandRegistry: return importlib.reload(module) def register(self, cmd: Command) -> None: + if cmd.name in self.commands: + logger.warn( + f"Command '{cmd.name}' already registered and will be overwritten!" + ) self.commands[cmd.name] = cmd def unregister(self, command_name: str): @@ -133,6 +139,11 @@ def command( ) -> Callable[..., Any]: """The command decorator is used to create Command objects from ordinary functions.""" + if not enabled: + if disabled_reason is not None: + logger.debug(f"Command '{name}' is disabled: {disabled_reason}") + return lambda func: func + def decorator(func: Callable[..., Any]) -> Command: cmd = Command( name=name,