diff --git a/scripts/refresh_data_dirs.py b/scripts/refresh_data_dirs.py index a7059e666..64568a753 100644 --- a/scripts/refresh_data_dirs.py +++ b/scripts/refresh_data_dirs.py @@ -27,7 +27,7 @@ import zipfile from collections.abc import Iterator from pathlib import Path from artifacts import file_lock as _file_lock, set_plain_mode -from common import github_token, platform_arg, require_platform, yaml_load +from common import github_token, platform_arg, require_platform, suggest_names, yaml_load try: import yaml @@ -607,7 +607,7 @@ def main() -> None: if args.key: if args.key not in registry: - log.error("unknown key: %s (available: %s)", args.key, ", ".join(registry)) + log.error("unknown key: %s. %s", args.key, suggest_names([args.key], list(registry), "--dry-run")) raise SystemExit(1) allowed = registry[args.key].get("for_platforms") if args.platform and allowed and args.platform not in allowed: diff --git a/tests/test_tool_messages.py b/tests/test_tool_messages.py index adfcdd59d..ca05417ed 100644 --- a/tests/test_tool_messages.py +++ b/tests/test_tool_messages.py @@ -83,6 +83,20 @@ class AMistypedTargetGetsTheClosestName(unittest.TestCase): self.assertNotIn("board-0", message) + +class AMistypedDataKeyGetsTheClosestName(unittest.TestCase): + """`--key dolphin-sis` printed all 27 keys on one line.""" + + def test_did_you_mean(self): + proc = subprocess.run( + [sys.executable, "scripts/refresh_data_dirs.py", "--key", "dolphin-sis", "--dry-run"], + cwd=REPO_ROOT, capture_output=True, text=True, check=False, + ) + self.assertEqual(proc.returncode, 1) + self.assertIn("unknown key: dolphin-sis. Did you mean: dolphin-sys? --dry-run lists all", + proc.stderr) + self.assertNotIn("ppsspp-assets", proc.stderr) + class TheTruthDiffShowsWhereAndAsksNothing(unittest.TestCase): """The markdown wrote `**Remove** hiscore.dat (phantom)` beside six `**Add** hiscore.dat`, none with a path, for files profiled cores read."""