From a54fd2f23582090a5043ba87537e70a263231b24 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Tue, 2 Feb 2021 12:15:20 +0800 Subject: [PATCH] :bulb: update docstring --- nonebot/__init__.py | 1 + nonebot/rule.py | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/nonebot/__init__.py b/nonebot/__init__.py index 9f9a0c37..db0d8277 100644 --- a/nonebot/__init__.py +++ b/nonebot/__init__.py @@ -12,6 +12,7 @@ - ``on_endswith`` => ``nonebot.plugin.on_endswith`` - ``on_keyword`` => ``nonebot.plugin.on_keyword`` - ``on_command`` => ``nonebot.plugin.on_command`` +- ``on_shell_command`` => ``nonebot.plugin.on_shell_command`` - ``on_regex`` => ``nonebot.plugin.on_regex`` - ``CommandGroup`` => ``nonebot.plugin.CommandGroup`` - ``Matchergroup`` => ``nonebot.plugin.MatcherGroup`` diff --git a/nonebot/rule.py b/nonebot/rule.py index ca0aa6db..eb00de57 100644 --- a/nonebot/rule.py +++ b/nonebot/rule.py @@ -280,6 +280,11 @@ def command(*cmds: Union[str, Tuple[str, ...]]) -> Rule: class ArgumentParser(ArgParser): + """ + :说明: + + ``shell_like`` 命令参数解析器,解析出错时不会退出程序。 + """ def _print_message(self, message, file=None): pass @@ -287,16 +292,11 @@ class ArgumentParser(ArgParser): def exit(self, status=0, message=None): raise ParserExit(status=status, message=message) - def parse_args( - self, - args: Optional[Sequence[str]] = None, - namespace: Optional[Namespace] = None - ) -> Union[ParserExit, Namespace]: - try: - return super().parse_args(args=args, - namespace=namespace) # type: ignore - except ParserExit as e: - return e + def parse_args(self, + args: Optional[Sequence[str]] = None, + namespace: Optional[Namespace] = None) -> Namespace: + return super().parse_args(args=args, + namespace=namespace) # type: ignore def shell_command(*cmds: Union[str, Tuple[str, ...]], @@ -361,8 +361,11 @@ def shell_command(*cmds: Union[str, Tuple[str, ...]], ):].lstrip() state["argv"] = shlex.split(strip_message) if parser: - args = parser.parse_args(state["argv"]) - state["args"] = args + try: + args = parser.parse_args(state["argv"]) + state["args"] = args + except ParserExit as e: + state["args"] = e return True else: return False