fix: suggest the nearest system or emulator name

This commit is contained in:
Abdessamad Derraz committed 2026-10-17 12:44:22 +02:00
1 parent c1c3808e1e
commit feb3b03a39
4 files changed
+33 -9

No files matched your search

+15 -1
View File
@@ -350,6 +350,20 @@ def list_registered_platforms(
return platforms
def suggest_names(typed: list[str], available: list[str], listing_flag: str) -> str:
"""The closest known names to what was typed, and how to see them all.
The hints showed the first ten or twenty names of the alphabet behind a
"..." whatever was typed: sony-playstaton listed 3do to apple-iie.
"""
import difflib # noqa: PLC0415
close = sorted({m for name in typed
for m in difflib.get_close_matches(name, available, n=3, cutoff=0.6)})
hint = f"Did you mean: {', '.join(close)}? " if close else ""
return f"{hint}{listing_flag} lists all {len(available)}."
def require_platform(name: str, platforms_dir: str = "platforms") -> None:
"""Exit with a usable message when no platform answers to a name.
@@ -1345,7 +1359,7 @@ def select_emulator_profiles(
)
raise ProfileSelectionError(
f"emulator '{name}' not found\n"
f"Available: {', '.join(available[:10])}..."
+ suggest_names([name], available, "--list-emulators")
)
profile = all_profiles[name]
kind = profile.get("type", "libretro")
+3 -4
View File
@@ -30,6 +30,7 @@ from pathlib import Path
sys.path.insert(0, os.path.dirname(__file__))
from common import resolve_platform_cores as _platform_cores
from common import (
suggest_names,
require_platform,
apply_target_overrides,
archive_entry,
@@ -1646,10 +1647,8 @@ def generate_system_pack(
f"No emulators found for system(s): {', '.join(system_ids)}",
file=sys.stderr,
)
print(
f"Available systems: {', '.join(sorted(all_systems)[:20])}...",
file=sys.stderr,
)
print(suggest_names(system_ids, sorted(all_systems), "--list-systems"),
file=sys.stderr)
return None
# Named like the platform's --system tag: one spelling of a system is
+3 -4
View File
@@ -34,6 +34,7 @@ import slots
sys.path.insert(0, os.path.dirname(__file__))
from common import (
suggest_names,
require_platform,
archive_entry,
archive_members,
@@ -1849,10 +1850,8 @@ def verify_system(
f"No emulators found for system(s): {', '.join(system_ids)}",
file=sys.stderr,
)
print(
f"Available systems: {', '.join(sorted(all_systems)[:20])}...",
file=sys.stderr,
)
print(suggest_names(system_ids, sorted(all_systems), "--list-systems"),
file=sys.stderr)
sys.exit(1)
return verify_emulator(