From 15aa4a80a11f32306ae109091dc0e8e4e9b0ccaf Mon Sep 17 00:00:00 2001 From: RF-Tar-Railt Date: Fri, 1 Nov 2024 01:16:14 +0800 Subject: [PATCH] :sparkles: basically wildcard pattern in query --- src/arclet/alconna/arparma.py | 5 +++++ src/arclet/alconna/core.py | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/arclet/alconna/arparma.py b/src/arclet/alconna/arparma.py index c5520c4..280452e 100644 --- a/src/arclet/alconna/arparma.py +++ b/src/arclet/alconna/arparma.py @@ -302,6 +302,11 @@ def __require__(self, parts: list[str]) -> tuple[Any, tuple[str, ...] | str | No """如果能够返回, 除开基本信息, 一定返回该path所在的dict""" bak = parts.copy() if len(bak) > 1: + if parts[0] == "*": + for _path in self.value_result: + if parts[1] in _path: + parts = list(_path) + break if parts[-1] == "value": parts.pop() if tuple(parts) in self.value_result: diff --git a/src/arclet/alconna/core.py b/src/arclet/alconna/core.py index f10965a..6a1fd60 100644 --- a/src/arclet/alconna/core.py +++ b/src/arclet/alconna/core.py @@ -52,7 +52,7 @@ def add_builtin_options(options: list[Option | Subcommand], router: Router, conf if "help" not in conf.disable_builtin_options: options.append(hlp := Help("|".join(conf.builtin_option_name["help"]), dest="$help", help_text=lang.require("builtin", "option_help"), soft_keyword=False)) # noqa: E501 - @router.route(hlp.name) + @router.route(f"*.{hlp.name}") @router.route("$help") def _(command: Alconna, arp: Arparma): _help_param = [str(i) for i in arp.buffer if str(i) not in conf.builtin_option_name["help"]] @@ -72,7 +72,7 @@ def _(command: Alconna, arp: Arparma): ) ) - @router.route(sct.name) + @router.route(f"*.{sct.name}") @router.route("$shortcut") def _(command: Alconna, arp: Arparma): res = arp.query[OptionResult]("$shortcut", force_return=True) @@ -94,7 +94,7 @@ def _(command: Alconna, arp: Arparma): if "completion" not in conf.disable_builtin_options: options.append(comp := Completion("|".join(conf.builtin_option_name["completion"]), dest="$completion", help_text=lang.require("builtin", "option_completion"), soft_keyword=False)) # noqa: E501 - @router.route(comp.name) + @router.route(f"*.{comp.name}") @router.route("$completion") def _(command: Alconna, arp: Arparma): rest = arp.buffer