Skip to content

Commit

Permalink
Fix commands with same name overwriting (Significant-Gravitas#4226)
Browse files Browse the repository at this point in the history
  • Loading branch information
k-boikov authored and ppetermann committed May 22, 2023
1 parent 83a0dc9 commit 8f53686
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions autogpt/commands/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
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"

Expand Down Expand Up @@ -59,6 +61,10 @@ def _reload_module(self, module: Any) -> Any:
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):
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8f53686

Please sign in to comment.