Skip to content

Commit

Permalink
✨ basically wildcard pattern in query
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Oct 31, 2024
1 parent df92d34 commit 15aa4a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/arclet/alconna/arparma.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/arclet/alconna/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 15aa4a8

Please sign in to comment.