From 379bbcc2ee3f068d23c35b69995aef5f3c6224f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B8=AD=E9=B8=AD=E3=80=8C=E3=82=AB=E3=83=A2=E3=80=8D?= <89643991+DuckDuckStudio@users.noreply.github.com> Date: Mon, 7 Sep 2026 22:07:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(ignore):=20=E5=9C=A8=20Ubuntu=20?= =?UTF-8?q?=E4=B8=8A=E6=94=AF=E6=8C=81=20list=20=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sundry.py | 33 +++++++++++++++++++++++++++------ tests/test_sundry.py | 17 +++++++++++++++++ 2 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 tests/test_sundry.py diff --git a/src/sundry.py b/src/sundry.py index c9e608f..cc329ed 100644 --- a/src/sundry.py +++ b/src/sundry.py @@ -8,6 +8,32 @@ from function.constant.paths import SUNDRY_LOCATION +def _can_it_run_on_non_windows_systems(tool: str, args: list[str]) -> bool: + """ + 判断该工具的操作是否可以在非 Windows 系统上运行。 + + Args: + tool: 要运行的工具 + args: 工具的参数 + + Returns: + True: 可以运行 + False: 不能运行 + """ + + if tool in [ + "移除", "remove", "自动移除", "autoremove", # 验证阶段需要 WinGet,不确定如何读取 Token + "单改", "单修改", "modify", "hash-update", # 验证清单需要 WinGet,不确定如何读取 Token + "verify", "test", "验证", "测试", # 仅 Windows + ]: + return False + + if tool in ("忽略", "检查忽略", "ignore"): + return bool(args and (args[0] in ("list", "--list", "列", "列出", "现有", "now"))) + + return True + + def main() -> int: init(autoreset=True) ajaw.load_translations() @@ -19,12 +45,7 @@ def main() -> int: tool = "help" args = [] - if (sys.platform != "win32") and (tool in ( - "移除", "remove", "自动移除", "autoremove", # 验证阶段需要 WinGet,不确定如何读取 Token - "单改", "单修改", "modify", "hash-update", # 验证清单需要 WinGet,不确定如何读取 Token - "忽略", "检查忽略", "ignore", # 不确定如何读取 Token - "verify", "test", "验证", "测试", # 仅 Windows - )): + if (sys.platform != "win32") and (not _can_it_run_on_non_windows_systems(tool, args)): print(f"{消息头.错误} 该操作仅可在 Windows 上运行") return 1 diff --git a/tests/test_sundry.py b/tests/test_sundry.py new file mode 100644 index 0000000..8cb9be2 --- /dev/null +++ b/tests/test_sundry.py @@ -0,0 +1,17 @@ +import pytest # noqa: I001 - 和 isort 冲突 + +from sundry import _can_it_run_on_non_windows_systems # pyright: ignore[reportPrivateUsage] + + +@pytest.mark.parametrize( + ("tool", "args", "excepted"), + [ + ("remove", [], False), + ("ignore", [], False), + ("ignore", ["add", "xxx"], False), + ("ignore", ["list"], True), + ("version", [], True) + ] +) +def test_can_it_run_on_non_windows_systems(tool: str, args: list[str], excepted: bool) -> None: + assert _can_it_run_on_non_windows_systems(tool, args) == excepted From b510449e711148e4a018528b224d8b30734ee822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B8=AD=E9=B8=AD=E3=80=8C=E3=82=AB=E3=83=A2=E3=80=8D?= <89643991+DuckDuckStudio@users.noreply.github.com> Date: Mon, 7 Sep 2026 22:25:53 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8E=9F=E5=9B=A0?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 鸭鸭「カモ」 <89643991+DuckDuckStudio@users.noreply.github.com> --- src/sundry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sundry.py b/src/sundry.py index cc329ed..82efa04 100644 --- a/src/sundry.py +++ b/src/sundry.py @@ -28,7 +28,7 @@ def _can_it_run_on_non_windows_systems(tool: str, args: list[str]) -> bool: ]: return False - if tool in ("忽略", "检查忽略", "ignore"): + if tool in ("忽略", "检查忽略", "ignore"): # 不确定如何读取 Token return bool(args and (args[0] in ("list", "--list", "列", "列出", "现有", "now"))) return True