fix(menu): 取消被误报为失败的根因修复,并容忍输入法全角 q

- 根因:worker 用 pwsh -Command '& 脚本' 调用时,脚本内的 exit 只结束脚本体,
  宿主进程按「最后一条命令是否成功」决定自己的退出码,于是取消(2)被报成 1
  修复:命令末尾补 '; exit \0' 显式传递退出码
- media-archive 的分类与确认输入先做 NFKC 归一化:中文输入法打出的全角
  「q」不再被判为未知分类并反复重试
- 实测:全角q取消 → 退出码 2;check 成功路径仍为 0
This commit is contained in:
ali
2026-11-19 18:54:28 +08:00
parent cc49b00e1f
commit 5b0a932bfc
2 changed files with 7 additions and 2 deletions
+3 -1
View File
@@ -154,7 +154,9 @@ function Invoke-Action([string]$itemAction, [string]$target) {
$quotedRunner = "'" + ($runnerPath -replace "'", "''") + "'" $quotedRunner = "'" + ($runnerPath -replace "'", "''") + "'"
$extra = '' $extra = ''
if ($DryRun) { $extra = ' -DryRun' } if ($DryRun) { $extra = ' -DryRun' }
$command = "& $quotedRunner -Tokens @($quotedTokens)$extra" # 末尾必须显式 exit:脚本里的 exit 只结束脚本体,-Command 宿主会按
# 「最后一条命令是否成功」给退出码,取消(code 2)会被错报成 1。
$command = "& $quotedRunner -Tokens @($quotedTokens)$extra; exit " + '$LASTEXITCODE'
$proc = Start-Process -FilePath $PwshPath ` $proc = Start-Process -FilePath $PwshPath `
-ArgumentList @('-NoLogo', '-NoProfile', '-ExecutionPolicy', 'Bypass', -ArgumentList @('-NoLogo', '-NoProfile', '-ExecutionPolicy', 'Bypass',
+4 -1
View File
@@ -27,6 +27,7 @@ import os
import re import re
import shutil import shutil
import sys import sys
import unicodedata
import urllib.error import urllib.error
import urllib.parse import urllib.parse
import urllib.request import urllib.request
@@ -357,6 +358,8 @@ def choose_category(cats: list[str], suggestion: str | None) -> str | None:
raw = input(f"\n请选择分类({hint},q 取消): ").strip() raw = input(f"\n请选择分类({hint},q 取消): ").strip()
except EOFError: except EOFError:
return None return None
# 中文输入法可能打出全角「q」「1」,先归一化再判断
raw = unicodedata.normalize("NFKC", raw)
if raw.lower() in {"q", "quit", "exit"}: if raw.lower() in {"q", "quit", "exit"}:
return None return None
if not raw: if not raw:
@@ -455,7 +458,7 @@ def main() -> int:
if not args.yes: if not args.yes:
try: try:
confirm = input("确认归档?[Y/n]: ").strip().lower() confirm = unicodedata.normalize("NFKC", input("确认归档?[Y/n]: ")).strip().lower()
except EOFError: except EOFError:
confirm = "n" confirm = "n"
if confirm not in {"", "y", "yes"}: if confirm not in {"", "y", "yes"}: