Skip to content

Commit

Permalink
sync: allow Argv for spec namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Nov 21, 2024
1 parent 2fea860 commit 10645e9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches:
- dev
- v2dev
- v1.8
- main
pull_request:

Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@
- Sistana (及其上游库)仅支持 Python 3.9 及以上版本。
- Sistana 对各种特性的兼容性尚未完全测试。

## 1.8.34

### 改进

- 允许为特定命名空间设置特定的 Argv 类型

## 1.8.33

### 改进

- 若快捷指令的 key 以 `^` 为前缀,则其会被替换为命令前缀之一,并发出警告
- 若快捷指令的 key 以 `^` 为前缀,则发出警告,然后 `^` 会被去除,并且对应的command会添加命令前缀之一

### 修复

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/arclet/alconna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion src/arclet/alconna/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 8 additions & 3 deletions src/arclet/alconna/ingedia/_argv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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}
)

Expand Down

0 comments on commit 10645e9

Please sign in to comment.