Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix commands with same name overwriting #4226

Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions autogpt/commands/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
import inspect
from typing import Any, Callable, Optional

from autogpt.config import Config
from autogpt.logs import logger

# Unique identifier for auto-gpt commands
AUTO_GPT_COMMAND_IDENTIFIER = "auto_gpt_command"

cfg = Config()
k-boikov marked this conversation as resolved.
Show resolved Hide resolved


class Command:
"""A class representing a command.
Expand Down Expand Up @@ -59,6 +64,10 @@
return importlib.reload(module)

def register(self, cmd: Command) -> None:
if cmd.name in self.commands:
logger.warn(

Check warning on line 68 in autogpt/commands/command.py

View check run for this annotation

Codecov / codecov/patch

autogpt/commands/command.py#L68

Added line #L68 was not covered by tests
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 +142,11 @@
) -> 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
Loading