Improve command lookup normalization

This commit is contained in:
陈家名
2026-06-25 15:43:30 +08:00
parent d229a9b022
commit 5babda196b
2 changed files with 17 additions and 2 deletions
+10 -2
View File
@@ -55,7 +55,8 @@ def command_names() -> list[str]:
def get_command(name: str) -> PortingModule | None:
needle = COMMAND_ALIASES.get(name.lower(), name.lower())
normalized = name.strip().lower()
needle = COMMAND_ALIASES.get(normalized, normalized)
for module in PORTED_COMMANDS:
if module.name.lower() == needle:
return module
@@ -72,8 +73,15 @@ def get_commands(cwd: str | None = None, include_plugin_commands: bool = True, i
def find_commands(query: str, limit: int = 20) -> list[PortingModule]:
needle = query.lower()
needle = query.strip().lower()
matches = [module for module in PORTED_COMMANDS if needle in module.name.lower() or needle in module.source_hint.lower()]
matches.sort(
key=lambda module: (
module.name.lower() != needle,
not module.name.lower().startswith(needle),
needle not in module.name.lower(),
)
)
return matches[:limit]