mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-08 20:39:44 +00:00
update
This commit is contained in:
0
pilot/commands/__init__.py
Normal file
0
pilot/commands/__init__.py
Normal file
36
pilot/commands/command.py
Normal file
36
pilot/commands/command.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import functools
|
||||||
|
import importlib
|
||||||
|
import inspect
|
||||||
|
from typing import Any, Callable, Optional
|
||||||
|
|
||||||
|
class Command:
|
||||||
|
"""A class representing a command.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
name (str): The name of the command.
|
||||||
|
description (str): A brief description of what the command does.
|
||||||
|
signature (str): The signature of the function that the command executes. Default to None.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self,
|
||||||
|
name: str,
|
||||||
|
description: str,
|
||||||
|
method: Callable[..., Any],
|
||||||
|
signature: str = "",
|
||||||
|
enabled: bool = True,
|
||||||
|
disabled_reason: Optional[str] = None,
|
||||||
|
) -> None:
|
||||||
|
self.name = name
|
||||||
|
self.description = description
|
||||||
|
self.method = method
|
||||||
|
self.signature = signature if signature else str(inspect.signature(self.method))
|
||||||
|
self.enabled = enabled
|
||||||
|
self.disabled_reason = disabled_reason
|
||||||
|
|
||||||
|
def __call__(self, *args: Any, **kwds: Any) -> Any:
|
||||||
|
if not self.enabled:
|
||||||
|
return f"Command '{self.name}' is disabled: {self.disabled_reason}"
|
||||||
|
return self.method(*args, **kwds)
|
Reference in New Issue
Block a user