ErisPulse 2.3.3__py3-none-any.whl → 2.3.4.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ErisPulse/Core/Event/wrapper.py +2 -3
- ErisPulse/Core/Event/wrapper.pyi +2 -3
- ErisPulse/Core/__init__.py +0 -5
- ErisPulse/Core/__init__.pyi +0 -1
- ErisPulse/__init__.py +0 -4
- ErisPulse/__init__.pyi +0 -1
- ErisPulse/sdk_protocol.py +0 -7
- ErisPulse/sdk_protocol.pyi +0 -3
- ErisPulse/utils/__init__.py +1 -1
- ErisPulse/utils/cli/__init__.py +11 -0
- ErisPulse/utils/cli/__init__.pyi +13 -0
- ErisPulse/utils/cli/__main__.py +225 -0
- ErisPulse/utils/cli/__main__.pyi +81 -0
- ErisPulse/utils/cli/base.py +52 -0
- ErisPulse/utils/cli/base.pyi +50 -0
- ErisPulse/utils/cli/commands/__init__.py +6 -0
- ErisPulse/utils/cli/commands/__init__.pyi +12 -0
- ErisPulse/utils/cli/commands/init.py +400 -0
- ErisPulse/utils/cli/commands/init.pyi +82 -0
- ErisPulse/utils/cli/commands/install.py +307 -0
- ErisPulse/utils/cli/commands/install.pyi +70 -0
- ErisPulse/utils/cli/commands/list.py +165 -0
- ErisPulse/utils/cli/commands/list.pyi +56 -0
- ErisPulse/utils/cli/commands/list_remote.py +128 -0
- ErisPulse/utils/cli/commands/list_remote.pyi +47 -0
- ErisPulse/utils/cli/commands/run.py +112 -0
- ErisPulse/utils/cli/commands/run.pyi +48 -0
- ErisPulse/utils/cli/commands/self_update.py +237 -0
- ErisPulse/utils/cli/commands/self_update.pyi +59 -0
- ErisPulse/utils/cli/commands/uninstall.py +37 -0
- ErisPulse/utils/cli/commands/uninstall.pyi +37 -0
- ErisPulse/utils/cli/commands/upgrade.py +62 -0
- ErisPulse/utils/cli/commands/upgrade.pyi +38 -0
- ErisPulse/utils/cli/registry.py +112 -0
- ErisPulse/utils/cli/registry.pyi +99 -0
- {erispulse-2.3.3.dist-info → erispulse-2.3.4.dev0.dist-info}/METADATA +6 -20
- erispulse-2.3.4.dev0.dist-info/RECORD +89 -0
- {erispulse-2.3.3.dist-info → erispulse-2.3.4.dev0.dist-info}/licenses/LICENSE +3 -3
- ErisPulse/Core/ux.py +0 -635
- ErisPulse/Core/ux.pyi +0 -94
- ErisPulse/utils/cli.py +0 -1097
- ErisPulse/utils/cli.pyi +0 -145
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/Bases/__init__.pyi +0 -14
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/Bases/adapter.pyi +0 -140
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/Bases/module.pyi +0 -52
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/Event/__init__.pyi +0 -26
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/Event/base.pyi +0 -62
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/Event/command.pyi +0 -113
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/Event/exceptions.pyi +0 -43
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/Event/message.pyi +0 -93
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/Event/meta.pyi +0 -92
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/Event/notice.pyi +0 -108
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/Event/request.pyi +0 -76
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/Event/wrapper.pyi +0 -404
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/__init__.pyi +0 -17
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/_self_config.pyi +0 -72
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/adapter.pyi +0 -229
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/config.pyi +0 -70
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/exceptions.pyi +0 -60
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/lifecycle.pyi +0 -92
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/logger.pyi +0 -168
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/module.pyi +0 -178
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/router.pyi +0 -120
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/storage.pyi +0 -273
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/Core/ux.pyi +0 -94
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/__init__.pyi +0 -310
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/__main__.pyi +0 -24
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/sdk_protocol.pyi +0 -100
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/utils/__init__.pyi +0 -16
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/utils/cli.pyi +0 -145
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/utils/console.pyi +0 -20
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/utils/package_manager.pyi +0 -224
- erispulse-2.3.3.data/data/ErisPulse-stubs/ErisPulse/utils/reload_handler.pyi +0 -64
- erispulse-2.3.3.dist-info/RECORD +0 -98
- {erispulse-2.3.3.dist-info → erispulse-2.3.4.dev0.dist-info}/WHEEL +0 -0
- {erispulse-2.3.3.dist-info → erispulse-2.3.4.dev0.dist-info}/entry_points.txt +0 -0
ErisPulse/Core/Event/wrapper.py
CHANGED
|
@@ -10,9 +10,8 @@ ErisPulse 事件包装类
|
|
|
10
10
|
{!--< /tips >!--}
|
|
11
11
|
"""
|
|
12
12
|
|
|
13
|
-
from typing import Any, Dict, List, Optional, Callable, Awaitable
|
|
13
|
+
from typing import Any, Dict, List, Optional, Callable, Awaitable
|
|
14
14
|
from .. import adapter, logger
|
|
15
|
-
import asyncio
|
|
16
15
|
|
|
17
16
|
|
|
18
17
|
class Event(dict):
|
|
@@ -479,7 +478,7 @@ class Event(dict):
|
|
|
479
478
|
"""
|
|
480
479
|
获取原始事件数据
|
|
481
480
|
|
|
482
|
-
:return:
|
|
481
|
+
:return: 原始事件数据字典
|
|
483
482
|
"""
|
|
484
483
|
platform = self.get_platform()
|
|
485
484
|
raw_key = f"{platform}_raw" if platform else "raw"
|
ErisPulse/Core/Event/wrapper.pyi
CHANGED
|
@@ -16,9 +16,8 @@ ErisPulse 事件包装类
|
|
|
16
16
|
{!--< /tips >!--}
|
|
17
17
|
"""
|
|
18
18
|
|
|
19
|
-
from typing import Any, Dict, List, Optional, Callable, Awaitable
|
|
19
|
+
from typing import Any, Dict, List, Optional, Callable, Awaitable
|
|
20
20
|
from .. import adapter, logger
|
|
21
|
-
import asyncio
|
|
22
21
|
|
|
23
22
|
class Event(dict):
|
|
24
23
|
"""
|
|
@@ -323,7 +322,7 @@ class Event(dict):
|
|
|
323
322
|
"""
|
|
324
323
|
获取原始事件数据
|
|
325
324
|
|
|
326
|
-
:return:
|
|
325
|
+
:return: 原始事件数据字典
|
|
327
326
|
"""
|
|
328
327
|
...
|
|
329
328
|
def get_raw_type(self: object) -> str:
|
ErisPulse/Core/__init__.py
CHANGED
|
@@ -6,7 +6,6 @@ from .logger import logger, Logger, LoggerChild
|
|
|
6
6
|
from .module import module, ModuleManager
|
|
7
7
|
from .router import router, RouterManager
|
|
8
8
|
from .config import config, ConfigManager
|
|
9
|
-
from .ux import ux, UXManager
|
|
10
9
|
from . import exceptions
|
|
11
10
|
from . import Event
|
|
12
11
|
|
|
@@ -43,10 +42,6 @@ __all__ = [
|
|
|
43
42
|
'RouterManager', # 路由管理器类
|
|
44
43
|
'adapter_server', # 路由管理器别名
|
|
45
44
|
|
|
46
|
-
# UX
|
|
47
|
-
'ux', # UX管理器实例
|
|
48
|
-
'UXManager', # UX管理器类
|
|
49
|
-
|
|
50
45
|
# 基础设施
|
|
51
46
|
'logger', # 日志管理器
|
|
52
47
|
'Logger', # 日志管理器类
|
ErisPulse/Core/__init__.pyi
CHANGED
|
@@ -12,6 +12,5 @@ from .logger import logger, Logger, LoggerChild
|
|
|
12
12
|
from .module import module, ModuleManager
|
|
13
13
|
from .router import router, RouterManager
|
|
14
14
|
from .config import config, ConfigManager
|
|
15
|
-
from .ux import ux, UXManager
|
|
16
15
|
from . import exceptions
|
|
17
16
|
from . import Event
|
ErisPulse/__init__.py
CHANGED
|
@@ -37,8 +37,6 @@ from .Core import adapter, AdapterFather, BaseAdapter, SendDSL
|
|
|
37
37
|
from .Core import module
|
|
38
38
|
# 路由相关
|
|
39
39
|
from .Core import router, adapter_server
|
|
40
|
-
# 用户体验相关
|
|
41
|
-
from .Core import ux, UXManager
|
|
42
40
|
|
|
43
41
|
# SDK统一对外接口
|
|
44
42
|
sdk: 'SDKProtocol' = types.ModuleType('sdk') # type: ignore[assignment]
|
|
@@ -71,8 +69,6 @@ BaseModules = {
|
|
|
71
69
|
|
|
72
70
|
"router": router,
|
|
73
71
|
"adapter_server": adapter_server,
|
|
74
|
-
"ux": ux,
|
|
75
|
-
"UXManager": UXManager,
|
|
76
72
|
}
|
|
77
73
|
|
|
78
74
|
for module_name, moduleObj in BaseModules.items():
|
ErisPulse/__init__.pyi
CHANGED
ErisPulse/sdk_protocol.py
CHANGED
|
@@ -17,7 +17,6 @@ from .Core.config import ConfigManager
|
|
|
17
17
|
from .Core.adapter import AdapterManager
|
|
18
18
|
from .Core.module import ModuleManager
|
|
19
19
|
from .Core.router import RouterManager
|
|
20
|
-
from .Core.ux import UXManager
|
|
21
20
|
from .Core.Bases.adapter import BaseAdapter, SendDSL
|
|
22
21
|
|
|
23
22
|
P = ParamSpec('P')
|
|
@@ -76,12 +75,6 @@ class SDKProtocol(Protocol):
|
|
|
76
75
|
adapter_server: RouterManager
|
|
77
76
|
"""路由管理器别名"""
|
|
78
77
|
|
|
79
|
-
ux: UXManager
|
|
80
|
-
"""UX管理器实例"""
|
|
81
|
-
|
|
82
|
-
UXManager: type[UXManager]
|
|
83
|
-
"""UX管理器类"""
|
|
84
|
-
|
|
85
78
|
# ==================== 初始化方法 ====================
|
|
86
79
|
|
|
87
80
|
async def init(self) -> bool:
|
ErisPulse/sdk_protocol.pyi
CHANGED
|
@@ -21,7 +21,6 @@ from .Core.config import ConfigManager
|
|
|
21
21
|
from .Core.adapter import AdapterManager
|
|
22
22
|
from .Core.module import ModuleManager
|
|
23
23
|
from .Core.router import RouterManager
|
|
24
|
-
from .Core.ux import UXManager
|
|
25
24
|
from .Core.Bases.adapter import BaseAdapter, SendDSL
|
|
26
25
|
|
|
27
26
|
class SDKProtocol(Protocol):
|
|
@@ -44,8 +43,6 @@ class SDKProtocol(Protocol):
|
|
|
44
43
|
module: ModuleManager
|
|
45
44
|
router: RouterManager
|
|
46
45
|
adapter_server: RouterManager
|
|
47
|
-
ux: UXManager
|
|
48
|
-
UXManager: type[UXManager]
|
|
49
46
|
async def init(self: object) -> bool:
|
|
50
47
|
"""
|
|
51
48
|
SDK初始化入口
|
ErisPulse/utils/__init__.py
CHANGED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"""
|
|
2
|
+
主 CLI 类
|
|
3
|
+
|
|
4
|
+
ErisPulse 命令行接口主入口
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import sys
|
|
8
|
+
import importlib
|
|
9
|
+
import importlib.metadata
|
|
10
|
+
import asyncio
|
|
11
|
+
import traceback
|
|
12
|
+
import pkgutil
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from argparse import ArgumentParser, RawDescriptionHelpFormatter
|
|
15
|
+
|
|
16
|
+
from rich.panel import Panel
|
|
17
|
+
|
|
18
|
+
from ..console import console
|
|
19
|
+
from .registry import CommandRegistry
|
|
20
|
+
from .base import Command
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class CLI:
|
|
24
|
+
"""
|
|
25
|
+
ErisPulse 命令行接口主类
|
|
26
|
+
|
|
27
|
+
提供完整的命令行交互功能,支持动态加载第三方命令
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
def __init__(self):
|
|
31
|
+
"""初始化 CLI"""
|
|
32
|
+
self.registry = CommandRegistry()
|
|
33
|
+
self.parser = self._create_parser()
|
|
34
|
+
self._register_builtin_commands()
|
|
35
|
+
self._load_external_commands()
|
|
36
|
+
|
|
37
|
+
def _create_parser(self) -> ArgumentParser:
|
|
38
|
+
"""
|
|
39
|
+
创建命令行参数解析器
|
|
40
|
+
|
|
41
|
+
:return: 配置好的 ArgumentParser 实例
|
|
42
|
+
"""
|
|
43
|
+
parser = ArgumentParser(
|
|
44
|
+
prog="epsdk",
|
|
45
|
+
formatter_class=RawDescriptionHelpFormatter,
|
|
46
|
+
description="ErisPulse SDK 命令行工具\n\n一个功能强大的模块化系统管理工具,用于管理ErisPulse生态系统中的模块、适配器和扩展。",
|
|
47
|
+
)
|
|
48
|
+
parser._positionals.title = "命令"
|
|
49
|
+
parser._optionals.title = "选项"
|
|
50
|
+
|
|
51
|
+
# 全局选项
|
|
52
|
+
parser.add_argument(
|
|
53
|
+
"--version", "-V",
|
|
54
|
+
action="store_true",
|
|
55
|
+
help="显示版本信息"
|
|
56
|
+
)
|
|
57
|
+
parser.add_argument(
|
|
58
|
+
"--verbose", "-v",
|
|
59
|
+
action="count",
|
|
60
|
+
default=0,
|
|
61
|
+
help="增加输出详细程度 (-v, -vv, -vvv)"
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# 子命令
|
|
65
|
+
subparsers = parser.add_subparsers(
|
|
66
|
+
dest='command',
|
|
67
|
+
metavar="<命令>",
|
|
68
|
+
help="要执行的操作"
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
self.subparsers = subparsers
|
|
72
|
+
return parser
|
|
73
|
+
|
|
74
|
+
def _auto_discover_commands(self):
|
|
75
|
+
"""
|
|
76
|
+
自动发现并注册 commands 目录中的所有命令
|
|
77
|
+
|
|
78
|
+
动态扫描 commands 目录,查找所有继承自 Command 基类的命令类
|
|
79
|
+
并自动注册到命令注册表中。
|
|
80
|
+
"""
|
|
81
|
+
# 获取 commands 包的路径
|
|
82
|
+
commands_package = 'ErisPulse.utils.cli.commands'
|
|
83
|
+
|
|
84
|
+
try:
|
|
85
|
+
# 遍历 commands 包中的所有模块
|
|
86
|
+
for importer, module_name, ispkg in pkgutil.iter_modules(
|
|
87
|
+
importlib.import_module(commands_package).__path__,
|
|
88
|
+
prefix=f"{commands_package}."
|
|
89
|
+
):
|
|
90
|
+
# 跳过 __init__ 和 __pycache__ 目录
|
|
91
|
+
if module_name.endswith('.__init__') or '__pycache__' in module_name:
|
|
92
|
+
continue
|
|
93
|
+
|
|
94
|
+
try:
|
|
95
|
+
# 动态导入模块
|
|
96
|
+
module = importlib.import_module(module_name)
|
|
97
|
+
|
|
98
|
+
# 查找模块中所有继承自 Command 的类
|
|
99
|
+
for attr_name in dir(module):
|
|
100
|
+
attr = getattr(module, attr_name)
|
|
101
|
+
|
|
102
|
+
# 检查是否是 Command 的子类(排除 Command 基类本身)
|
|
103
|
+
if (isinstance(attr, type) and
|
|
104
|
+
issubclass(attr, Command) and
|
|
105
|
+
attr is not Command):
|
|
106
|
+
try:
|
|
107
|
+
# 实例化并注册命令
|
|
108
|
+
command_instance = attr()
|
|
109
|
+
self.registry.register(command_instance)
|
|
110
|
+
except Exception as e:
|
|
111
|
+
console.print(f"[warning]实例化命令 {attr_name} 失败: {e}[/]")
|
|
112
|
+
|
|
113
|
+
except Exception as e:
|
|
114
|
+
console.print(f"[warning]加载命令模块 {module_name} 失败: {e}[/]")
|
|
115
|
+
|
|
116
|
+
except ImportError as e:
|
|
117
|
+
console.print(f"[warning]无法导入 commands 包: {e}[/]")
|
|
118
|
+
|
|
119
|
+
def _register_builtin_commands(self):
|
|
120
|
+
"""注册所有内置命令(通过自动发现)"""
|
|
121
|
+
self._auto_discover_commands()
|
|
122
|
+
|
|
123
|
+
# 添加所有命令的参数
|
|
124
|
+
for command in self.registry.get_all():
|
|
125
|
+
parser = self.subparsers.add_parser(
|
|
126
|
+
command.name,
|
|
127
|
+
help=command.description
|
|
128
|
+
)
|
|
129
|
+
command.add_arguments(parser)
|
|
130
|
+
|
|
131
|
+
def _load_external_commands(self):
|
|
132
|
+
"""
|
|
133
|
+
加载第三方 CLI 命令
|
|
134
|
+
"""
|
|
135
|
+
try:
|
|
136
|
+
entry_points = importlib.metadata.entry_points()
|
|
137
|
+
if hasattr(entry_points, 'select'):
|
|
138
|
+
cli_entries = entry_points.select(group='erispulse.cli')
|
|
139
|
+
else:
|
|
140
|
+
cli_entries = entry_points.get('erispulse.cli', [])
|
|
141
|
+
|
|
142
|
+
for entry in cli_entries:
|
|
143
|
+
try:
|
|
144
|
+
cli_func = entry.load()
|
|
145
|
+
if callable(cli_func):
|
|
146
|
+
# 传入 subparsers 和 console,保持兼容性
|
|
147
|
+
cli_func(self.subparsers, console)
|
|
148
|
+
else:
|
|
149
|
+
console.print(f"[warning]模块 {entry.name} 的入口点不是可调用对象[/]")
|
|
150
|
+
except Exception as e:
|
|
151
|
+
console.print(f"[error]加载第三方命令 {entry.name} 失败: {e}[/]")
|
|
152
|
+
except Exception as e:
|
|
153
|
+
console.print(f"[warning]加载第三方CLI命令失败: {e}[/]")
|
|
154
|
+
|
|
155
|
+
def _print_version(self):
|
|
156
|
+
"""打印版本信息"""
|
|
157
|
+
from ErisPulse import __version__
|
|
158
|
+
console.print(Panel(
|
|
159
|
+
f"[title]ErisPulse SDK[/] 版本: [bold]{__version__}[/]",
|
|
160
|
+
subtitle=f"Python {sys.version.split()[0]}",
|
|
161
|
+
style="title"
|
|
162
|
+
))
|
|
163
|
+
|
|
164
|
+
def run(self):
|
|
165
|
+
"""
|
|
166
|
+
运行 CLI
|
|
167
|
+
|
|
168
|
+
:raises KeyboardInterrupt: 用户中断时抛出
|
|
169
|
+
:raises Exception: 命令执行失败时抛出
|
|
170
|
+
"""
|
|
171
|
+
args = self.parser.parse_args()
|
|
172
|
+
|
|
173
|
+
# 处理版本选项
|
|
174
|
+
if args.version:
|
|
175
|
+
self._print_version()
|
|
176
|
+
return
|
|
177
|
+
|
|
178
|
+
# 没有指定命令时显示帮助
|
|
179
|
+
if not args.command:
|
|
180
|
+
self.parser.print_help()
|
|
181
|
+
return
|
|
182
|
+
|
|
183
|
+
try:
|
|
184
|
+
# 执行命令
|
|
185
|
+
command = self.registry.get(args.command)
|
|
186
|
+
if command:
|
|
187
|
+
command.execute(args)
|
|
188
|
+
else:
|
|
189
|
+
# 第三方命令处理
|
|
190
|
+
self._execute_external_command(args)
|
|
191
|
+
|
|
192
|
+
except KeyboardInterrupt:
|
|
193
|
+
console.print("\n[warning]操作被用户中断[/]")
|
|
194
|
+
sys.exit(1)
|
|
195
|
+
except Exception as e:
|
|
196
|
+
console.print(f"[error]执行命令时出错: {e}[/]")
|
|
197
|
+
if args.verbose >= 1:
|
|
198
|
+
console.print(traceback.format_exc())
|
|
199
|
+
sys.exit(1)
|
|
200
|
+
|
|
201
|
+
def _execute_external_command(self, args):
|
|
202
|
+
"""
|
|
203
|
+
执行第三方命令
|
|
204
|
+
|
|
205
|
+
:param args: 解析后的参数
|
|
206
|
+
"""
|
|
207
|
+
try:
|
|
208
|
+
# 第三方命令在注册时已经通过 set_defaults(func=handle_command) 设置了处理函数
|
|
209
|
+
# 所以 args.func 就是处理函数
|
|
210
|
+
if hasattr(args, 'func') and args.func:
|
|
211
|
+
handler_func = args.func
|
|
212
|
+
if asyncio.iscoroutinefunction(handler_func):
|
|
213
|
+
# 异步函数:使用 asyncio.run() 运行
|
|
214
|
+
asyncio.run(handler_func(args))
|
|
215
|
+
else:
|
|
216
|
+
# 同步函数:直接调用
|
|
217
|
+
handler_func(args)
|
|
218
|
+
else:
|
|
219
|
+
console.print(f"[error]命令 {args.command} 没有处理函数[/]")
|
|
220
|
+
sys.exit(1)
|
|
221
|
+
except Exception as e:
|
|
222
|
+
console.print(f"[error]执行第三方命令失败: {e}[/]")
|
|
223
|
+
if args.verbose >= 1:
|
|
224
|
+
console.print(traceback.format_exc())
|
|
225
|
+
sys.exit(1)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# type: ignore
|
|
2
|
+
#
|
|
3
|
+
# Auto-generated type stub for __main__.py
|
|
4
|
+
# DO NOT EDIT MANUALLY - Generated by generate-type-stubs.py
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
主 CLI 类
|
|
9
|
+
|
|
10
|
+
ErisPulse 命令行接口主入口
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import sys
|
|
14
|
+
import importlib
|
|
15
|
+
import importlib.metadata
|
|
16
|
+
import asyncio
|
|
17
|
+
import traceback
|
|
18
|
+
import pkgutil
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
from argparse import ArgumentParser, RawDescriptionHelpFormatter
|
|
21
|
+
from rich.panel import Panel
|
|
22
|
+
from ..console import console
|
|
23
|
+
from .registry import CommandRegistry
|
|
24
|
+
from .base import Command
|
|
25
|
+
|
|
26
|
+
class CLI:
|
|
27
|
+
"""
|
|
28
|
+
ErisPulse 命令行接口主类
|
|
29
|
+
|
|
30
|
+
提供完整的命令行交互功能,支持动态加载第三方命令
|
|
31
|
+
"""
|
|
32
|
+
def __init__(self: None) -> ...:
|
|
33
|
+
"""
|
|
34
|
+
初始化 CLI
|
|
35
|
+
"""
|
|
36
|
+
...
|
|
37
|
+
def _create_parser(self: object) -> ArgumentParser:
|
|
38
|
+
"""
|
|
39
|
+
创建命令行参数解析器
|
|
40
|
+
|
|
41
|
+
:return: 配置好的 ArgumentParser 实例
|
|
42
|
+
"""
|
|
43
|
+
...
|
|
44
|
+
def _auto_discover_commands(self: object) -> ...:
|
|
45
|
+
"""
|
|
46
|
+
自动发现并注册 commands 目录中的所有命令
|
|
47
|
+
|
|
48
|
+
动态扫描 commands 目录,查找所有继承自 Command 基类的命令类
|
|
49
|
+
并自动注册到命令注册表中。
|
|
50
|
+
"""
|
|
51
|
+
...
|
|
52
|
+
def _register_builtin_commands(self: object) -> ...:
|
|
53
|
+
"""
|
|
54
|
+
注册所有内置命令(通过自动发现)
|
|
55
|
+
"""
|
|
56
|
+
...
|
|
57
|
+
def _load_external_commands(self: object) -> ...:
|
|
58
|
+
"""
|
|
59
|
+
加载第三方 CLI 命令
|
|
60
|
+
"""
|
|
61
|
+
...
|
|
62
|
+
def _print_version(self: object) -> ...:
|
|
63
|
+
"""
|
|
64
|
+
打印版本信息
|
|
65
|
+
"""
|
|
66
|
+
...
|
|
67
|
+
def run(self: object) -> ...:
|
|
68
|
+
"""
|
|
69
|
+
运行 CLI
|
|
70
|
+
|
|
71
|
+
:raises KeyboardInterrupt: 用户中断时抛出
|
|
72
|
+
:raises Exception: 命令执行失败时抛出
|
|
73
|
+
"""
|
|
74
|
+
...
|
|
75
|
+
def _execute_external_command(self: object, args: ...) -> ...:
|
|
76
|
+
"""
|
|
77
|
+
执行第三方命令
|
|
78
|
+
|
|
79
|
+
:param args: 解析后的参数
|
|
80
|
+
"""
|
|
81
|
+
...
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CLI 命令基类
|
|
3
|
+
|
|
4
|
+
定义所有命令的统一接口
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from abc import ABC, abstractmethod
|
|
8
|
+
from argparse import ArgumentParser
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Command(ABC):
|
|
12
|
+
"""
|
|
13
|
+
命令基类
|
|
14
|
+
|
|
15
|
+
所有 CLI 命令都应继承此类并实现抽象方法
|
|
16
|
+
|
|
17
|
+
{!--< tips >!--}
|
|
18
|
+
1. 每个命令类必须实现 add_arguments 和 execute 方法
|
|
19
|
+
2. name 和 description 为类属性,必须在子类中定义
|
|
20
|
+
3. execute 方法接收解析后的 args 对象
|
|
21
|
+
{!--< /tips >!--}
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
name: str = "" # 命令名称
|
|
25
|
+
description: str = "" # 命令描述
|
|
26
|
+
|
|
27
|
+
@abstractmethod
|
|
28
|
+
def add_arguments(self, parser: ArgumentParser):
|
|
29
|
+
"""
|
|
30
|
+
添加命令参数
|
|
31
|
+
|
|
32
|
+
:param parser: ArgumentParser 实例
|
|
33
|
+
"""
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
@abstractmethod
|
|
37
|
+
def execute(self, args):
|
|
38
|
+
"""
|
|
39
|
+
执行命令
|
|
40
|
+
|
|
41
|
+
:param args: 解析后的参数对象
|
|
42
|
+
"""
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def help(self) -> str:
|
|
47
|
+
"""
|
|
48
|
+
获取帮助信息
|
|
49
|
+
|
|
50
|
+
:return: 命令描述
|
|
51
|
+
"""
|
|
52
|
+
return self.description
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# type: ignore
|
|
2
|
+
#
|
|
3
|
+
# Auto-generated type stub for base.py
|
|
4
|
+
# DO NOT EDIT MANUALLY - Generated by generate-type-stubs.py
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
CLI 命令基类
|
|
9
|
+
|
|
10
|
+
定义所有命令的统一接口
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from abc import ABC, abstractmethod
|
|
14
|
+
from argparse import ArgumentParser
|
|
15
|
+
|
|
16
|
+
class Command(ABC):
|
|
17
|
+
"""
|
|
18
|
+
命令基类
|
|
19
|
+
|
|
20
|
+
所有 CLI 命令都应继承此类并实现抽象方法
|
|
21
|
+
|
|
22
|
+
{!--< tips >!--}
|
|
23
|
+
1. 每个命令类必须实现 add_arguments 和 execute 方法
|
|
24
|
+
2. name 和 description 为类属性,必须在子类中定义
|
|
25
|
+
3. execute 方法接收解析后的 args 对象
|
|
26
|
+
{!--< /tips >!--}
|
|
27
|
+
"""
|
|
28
|
+
name: str
|
|
29
|
+
description: str
|
|
30
|
+
def add_arguments(self: object, parser: ArgumentParser) -> ...:
|
|
31
|
+
"""
|
|
32
|
+
添加命令参数
|
|
33
|
+
|
|
34
|
+
:param parser: ArgumentParser 实例
|
|
35
|
+
"""
|
|
36
|
+
...
|
|
37
|
+
def execute(self: object, args: ...) -> ...:
|
|
38
|
+
"""
|
|
39
|
+
执行命令
|
|
40
|
+
|
|
41
|
+
:param args: 解析后的参数对象
|
|
42
|
+
"""
|
|
43
|
+
...
|
|
44
|
+
def help(self: object) -> str:
|
|
45
|
+
"""
|
|
46
|
+
获取帮助信息
|
|
47
|
+
|
|
48
|
+
:return: 命令描述
|
|
49
|
+
"""
|
|
50
|
+
...
|