Skip to content

Commit

Permalink
🔥 remove deprecated design
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Oct 12, 2024
1 parent b7a0b4c commit 63ee1bb
Show file tree
Hide file tree
Showing 19 changed files with 268 additions and 918 deletions.
113 changes: 107 additions & 6 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions src/arclet/alconna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from .config import config as config
from .config import namespace as namespace
from .core import Alconna as Alconna
from .duplication import Duplication as Duplication
from .exceptions import AlconnaException as AlconnaException
from .exceptions import InvalidArgs as InvalidArgs
from .exceptions import InvalidParam as InvalidParam
Expand All @@ -40,9 +39,6 @@
from .model import OptionResult as OptionResult
from .model import SubcommandResult as SubcommandResult
from .output import output_manager as output_manager
from .stub import ArgsStub as ArgsStub
from .stub import OptionStub as OptionStub
from .stub import SubcommandStub as SubcommandStub
from .typing import AllParam as AllParam
from .typing import CommandMeta as CommandMeta
from .typing import KeyWordVar as KeyWordVar
Expand Down
36 changes: 4 additions & 32 deletions src/arclet/alconna/_internal/_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
SpecialOptionTriggered,
)
from ..manager import command_manager
from ..model import HeadResult, OptionResult, Sentence, SubcommandResult
from ..model import HeadResult, OptionResult, SubcommandResult
from ..output import output_manager
from ..typing import TDC, InnerShortcutArgs
from ._handlers import (
Expand All @@ -49,29 +49,6 @@
_SPECIAL = {"help": handle_help, "shortcut": handle_shortcut, "completion": handle_completion}


def _compile_opts(option: Option, data: dict[str, Sentence | Option | list[Option] | SubAnalyser]):
"""处理选项
Args:
option (Option): 选项
data (dict[str, Sentence | Option | list[Option] | SubAnalyser]): 编译的节点
"""
for alias in option.aliases:
if li := data.get(alias):
if isinstance(li, SubAnalyser):
continue
if isinstance(li, list):
li.append(option)
li.sort(key=lambda x: x.priority, reverse=True)
elif isinstance(li, Sentence):
data[alias] = option
continue
else:
data[alias] = sorted([li, option], key=lambda x: x.priority, reverse=True)
else:
data[alias] = option


def default_compiler(analyser: SubAnalyser, pids: set[str]):
"""默认的编译方法
Expand All @@ -83,7 +60,8 @@ def default_compiler(analyser: SubAnalyser, pids: set[str]):
if isinstance(opts, Option) and not isinstance(opts, (Help, Shortcut, Completion)):
if opts.compact or opts.action.type == 2 or not set(analyser.command.separators).issuperset(opts.separators): # noqa: E501
analyser.compact_params.append(opts)
_compile_opts(opts, analyser.compile_params) # type: ignore
for alias in opts.aliases:
analyser.compile_params[alias] = opts
if opts.default is not Empty:
analyser.default_opt_result[opts.dest] = (opts.default, opts.action)
pids.update(opts.aliases)
Expand All @@ -97,10 +75,6 @@ def default_compiler(analyser: SubAnalyser, pids: set[str]):
analyser.compact_params.append(sub)
if sub.command.default is not Empty:
analyser.default_sub_result[opts.dest] = sub.command.default
if opts.requires:
pids.update(opts.requires)
for k in opts.requires:
analyser.compile_params.setdefault(k, Sentence(name=k))


@dataclass
Expand All @@ -113,7 +87,7 @@ class SubAnalyser(Generic[TDC]):
"""命令是否只有主参数"""
need_main_args: bool = field(default=False)
"""是否需要主参数"""
compile_params: dict[str, Sentence | Option | list[Option] | SubAnalyser[TDC]] = field(default_factory=dict)
compile_params: dict[str, Option | SubAnalyser[TDC]] = field(default_factory=dict)
"""编译的节点"""
compact_params: list[Option | SubAnalyser[TDC]] = field(default_factory=list)
"""可能紧凑的需要逐个解析的节点"""
Expand All @@ -129,8 +103,6 @@ class SubAnalyser(Generic[TDC]):
"""头部的解析结果"""
value_result: Any = field(init=False)
"""值的解析结果"""
sentences: list[str] = field(init=False)
"""暂存传入的所有句段"""
default_opt_result: dict[str, tuple[OptionResult, Action]] = field(default_factory=dict)
"""默认选项的解析结果"""
default_sub_result: dict[str, SubcommandResult] = field(default_factory=dict)
Expand Down
Loading

0 comments on commit 63ee1bb

Please sign in to comment.