Skip to content

Commit

Permalink
🔖 version 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Sep 19, 2022
1 parent ff82e19 commit ec12208
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 78 deletions.
14 changes: 11 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Alconna 1.2.x:
# Alconna 1.23.x:

## Alconna 1.2.1
## Alconna 1.3.0
1. 修复 bugs
2. 完善命令补全功能
2. 调整 Alconna的构造样式, 将header、command、options等合并; 兼容旧版写法到1.4
3. 原先的builtins迁移至[`arclet-alconna-tools`](https://github.com/ArcletProject/Alconna-Tools), 只保留set_default、store_value与version
4. `set_default`可以附加一个 arg 名
5. 调整repr样式
6. 取消 shortcut的expiration
7. 新增命名空间配置,并将原先部分全局配置划为命名空间下的配置
8. 允许.parse传入参数interrupt(bool)以在参数缺失的情况下可后续自行加参数

# Alconna 1.2.x:

## Alconna 1.2.0 ~ 1.2.0.7:
1. 修复 bugs
Expand Down
81 changes: 33 additions & 48 deletions pdm.lock

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

8 changes: 4 additions & 4 deletions src/arclet/alconna/analysis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from .analyser import Analyser
from .parts import analyse_args as ala, analyse_header as alh, analyse_option as alo, analyse_subcommand as als
from ..typing import DataCollection
from ..typing import DataCollection, TDataCollection
from ..base import Option, Subcommand, Sentence
from ..args import Args

Expand All @@ -26,7 +26,7 @@ def default_params_parser(analyser: "Analyser"):
require_len = 0
for opts in analyser.alconna.options:
if isinstance(opts, Option):
_compile_opts(opts, analyser.command_params)
_compile_opts(opts, analyser.command_params) # type: ignore
analyser.param_ids.update(opts.aliases)
elif isinstance(opts, Subcommand):
sub_require_len = 0
Expand Down Expand Up @@ -58,7 +58,7 @@ def compile(alconna: "Alconna", params_parser: Callable[[Analyser], None] = defa
return _analyser


def analyse(alconna: "Alconna", command: DataCollection[Union[str, Any]]) -> "Arpamar":
def analyse(alconna: "Alconna", command: TDataCollection) -> "Arpamar[TDataCollection]":
return compile(alconna).process(command).analyse().execute()


Expand All @@ -82,7 +82,7 @@ def __new__(cls, *args, **kwargs):
cls.message_cache = False
return super().__new__(cls)

def analyse(self, message: Union[DataCollection[Union[str, Any]], None] = None):
def analyse(self, message=None, interrupt=False):
pass


Expand Down
2 changes: 1 addition & 1 deletion src/arclet/alconna/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def __getitem__(self, item) -> Union["Args", Tuple[TAValue, ArgField]]:
if isinstance(item, str) and self.argument.get(item):
return self.argument[item]['value'], self.argument[item]['field']
if isinstance(item, slice) or isinstance(item, tuple) and list(filter(lambda x: isinstance(x, slice), item)):
raise InvalidParam(f"{self.__name__} 现在不支持切片; 应从 Args[a:b:c, x:y:z] 变为 Args[a,b,c][x,y,z]")
raise InvalidParam(f"{self.__class__.__name__} 现在不支持切片; 应从 Args[a:b:c, x:y:z] 变为 Args[a,b,c][x,y,z]")
if not isinstance(item, tuple):
self.__check_var__([str(item), item])
else:
Expand Down
43 changes: 21 additions & 22 deletions src/arclet/alconna/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from .components.behavior import T_ABehavior
from .components.duplication import Duplication


T_Duplication = TypeVar('T_Duplication', bound=Duplication)
T_Header = Union[List[Union[str, object]], List[Tuple[object, str]]]

Expand Down Expand Up @@ -143,7 +142,7 @@ class Alconna(CommandNode):
headers: Union[List[Union[str, object]], List[Tuple[object, str]]]
command: Union[str, Any]
options: List[Union[Option, Subcommand]]
analyser_type: Type["TAnalyser"]
analyser_type: Type[Analyser]
formatter_type: Type[TextFormatter]
namespace: str
meta: CommandMeta
Expand All @@ -157,11 +156,11 @@ class Alconna(CommandNode):

@classmethod
def config(
cls,
*,
behaviors: Optional[List[T_ABehavior]] = None,
analyser_type: Optional[Type["TAnalyser"]] = None,
formatter_type: Optional[Type[TextFormatter]] = None,
cls,
*,
behaviors: Optional[List[T_ABehavior]] = None,
analyser_type: Optional[Type[TAnalyser]] = None,
formatter_type: Optional[Type[TextFormatter]] = None,
):
"""
配置 Alconna 的默认属性
Expand All @@ -181,7 +180,7 @@ def __init__(
meta: Optional[CommandMeta] = None,
namespace: Optional[Union[str, Namespace]] = None,
separators: Optional[Union[str, Iterable[str]]] = None,
analyser_type: Optional[Type["TAnalyser"]] = None,
analyser_type: Optional[Type[TAnalyser]] = None,
behaviors: Optional[List[T_ABehavior]] = None,
formatter_type: Optional[Type[TextFormatter]] = None,
**kwargs
Expand All @@ -205,7 +204,7 @@ def __init__(
np_config = config.namespaces.setdefault(namespace.name, namespace)
else:
np_config = config.namespaces.setdefault(namespace, Namespace(namespace))
self.headers = next(filter(lambda x: isinstance(x, list), args + (np_config.headers, )))
self.headers = next(filter(lambda x: isinstance(x, list), args + (np_config.headers,))) # type: ignore
try:
self.command = next(filter(lambda x: not isinstance(x, (list, Option, Subcommand, Args)), args))
except StopIteration:
Expand All @@ -214,7 +213,7 @@ def __init__(
self.action_list = {"options": {}, "subcommands": {}, "main": None}
self.namespace = np_config.name
self.options.extend([HelpOption, ShortcutOption, CompletionOption])
self.analyser_type = analyser_type or self.__class__.global_analyser_type
self.analyser_type = analyser_type or self.__class__.global_analyser_type # type: ignore
self.behaviors = behaviors or self.__class__.global_behaviors.copy()
self.behaviors.insert(0, ActionHandler())
self.formatter_type = formatter_type or self.__class__.global_formatter_type
Expand All @@ -227,7 +226,7 @@ def __init__(
action=action,
separators=separators or np_config.separators.copy(), # type: ignore
)
self.name = f"{self.command or self.headers[0]}".replace(command_manager.sign, "")
self.name = f"{self.command or self.headers[0]}".replace(command_manager.sign, "") # type: ignore
self._deprecate(kwargs)
self._hash = self._calc_hash()
command_manager.register(self)
Expand Down Expand Up @@ -256,13 +255,13 @@ def _deprecate(self, kwargs):
)
if key == "help_text":
warnings.warn("'help_text' will not support in 1.4.0 !", DeprecationWarning, 2)
self.meta.description = value
self.meta.description = str(value)
if key == "raise_exception":
warnings.warn("'raise_exception' will not support in 1.4.0 !", DeprecationWarning, 2)
self.meta.raise_exception = value
self.meta.raise_exception = bool(value)
if key == "is_fuzzy_match":
warnings.warn("'is_fuzzy_match' will not support in 1.4.0 !", DeprecationWarning, 2)
self.meta.fuzzy_match = value
self.meta.fuzzy_match = bool(value)

def __union__(self, other: Union["Alconna", AlconnaGroup]) -> AlconnaGroup:
"""
Expand Down Expand Up @@ -308,7 +307,7 @@ def set_custom_types(cls, **types: Type):
cls.custom_types = types

def shortcut(
self, short_key: str, command: Optional[TDataCollection] = None, delete: bool = False
self, short_key: str, command: Optional[TDataCollection] = None, delete: bool = False
):
"""添加快捷命令"""
try:
Expand Down Expand Up @@ -350,26 +349,26 @@ def add(self, name: str, *alias: str, args: Optional[Args] = None, sep: str = "

@overload
def parse(
self, message: TDataCollection, duplication: Type[T_Duplication], static: bool = True, interrupt: bool = False
self, message, duplication: Type[T_Duplication], static=True, interrupt=False
) -> T_Duplication:
...

@overload
def parse(
self, message: TDataCollection, duplication=None, static: bool = True, interrupt: bool = False
self, message: TDataCollection, duplication=None, static=True, interrupt=False
) -> Arpamar[TDataCollection]:
...

@overload
def parse(
self, message: TDataCollection, duplication=..., static: bool = True, interrupt: bool = True
) -> TAnalyser:
self, message, duplication=None, static=True, interrupt=True
) -> Analyser:
...

def parse(
self, message: TDataCollection, duplication: Optional[Type[T_Duplication]] = None,
static: bool = True, interrupt: bool = False
):
self, message: TDataCollection, duplication: Optional[Type[T_Duplication]] = None,
static: bool = True, interrupt: bool = False
) -> Union[Analyser, Arpamar[TDataCollection], T_Duplication]:
"""命令分析功能, 传入字符串或消息链, 返回一个特定的数据集合类"""
analyser = command_manager.require(self) if static else compile(self)
analyser.process(message)
Expand Down

0 comments on commit ec12208

Please sign in to comment.