diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 503c836e..ac701b30 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,7 @@ on: push: branches: - dev - - v2dev + - v1.8 - main pull_request: diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a00e171..87456b43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,11 +11,17 @@ - Sistana (及其上游库)仅支持 Python 3.9 及以上版本。 - Sistana 对各种特性的兼容性尚未完全测试。 +## 1.8.34 + +### 改进 + +- 允许为特定命名空间设置特定的 Argv 类型 + ## 1.8.33 ### 改进 -- 若快捷指令的 key 以 `^` 为前缀,则其会被替换为命令前缀之一,并发出警告 +- 若快捷指令的 key 以 `^` 为前缀,则发出警告,然后 `^` 会被去除,并且对应的command会添加命令前缀之一 ### 修复 diff --git a/pyproject.toml b/pyproject.toml index 42298008..4bb42b96 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ authors = [ ] dependencies = [ "typing-extensions>=4.5.0", - "nepattern<1.1.0,>=1.0.0", + "nepattern<1.1.0,>=1.0.1", "tarina<0.7.0,>=0.6.1", "elaina-segment>=0.4.0", "elaina-flywheel>=0.6.0", diff --git a/src/arclet/alconna/__init__.py b/src/arclet/alconna/__init__.py index 5822cba0..b2f34b44 100644 --- a/src/arclet/alconna/__init__.py +++ b/src/arclet/alconna/__init__.py @@ -39,4 +39,4 @@ from .shortcut import ShortcutArgs as ShortcutArgs from .manager import command_manager as command_manager -__version__ = "1.8.33" +__version__ = "1.8.34" diff --git a/src/arclet/alconna/core.py b/src/arclet/alconna/core.py index 3965adc0..d3a471af 100644 --- a/src/arclet/alconna/core.py +++ b/src/arclet/alconna/core.py @@ -212,7 +212,7 @@ def compile(self) -> Analyser: if TYPE_CHECKING: argv_type = Argv else: - argv_type: type[Argv] = __argv_type__.get() + argv_type: type[Argv] = __argv_type__.get(self.namespace, __argv_type__["_"]) argv = argv_type(self.config, self.namespace_config, self.separators) return Analyser(self, argv) diff --git a/src/arclet/alconna/ingedia/_argv.py b/src/arclet/alconna/ingedia/_argv.py index 5020b73d..d58a4a06 100644 --- a/src/arclet/alconna/ingedia/_argv.py +++ b/src/arclet/alconna/ingedia/_argv.py @@ -272,12 +272,17 @@ def exit(self) -> dict[str, Any]: return _ -__argv_type__: ContextVar[type[Argv]] = ContextVar("argv_type", default=Argv) +__argv_type__: dict[str, type[Argv]] = {"_": Argv} def set_default_argv_type(argv_type: type[Argv]): """设置默认的命令行参数类型""" - __argv_type__.set(argv_type) + __argv_type__["_"] = argv_type + + +def set_namespace_argv_type(namespace: str, argv_type: type[Argv]): + """设置命名空间的命令行参数类型""" + __argv_type__[namespace] = argv_type def argv_config( @@ -296,7 +301,7 @@ def argv_config( checker (Callable[[Any], bool] | None, optional): 检查传入命令. converter (Callable[[str | list], TDC] | None, optional): 将字符串或列表转为目标命令类型. """ - Argv._cache.setdefault(target or __argv_type__.get(), {}).update( + Argv._cache.setdefault(target or __argv_type__["_"], {}).update( {k: v for k, v in locals().items() if v is not None} )