mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-30 21:38:55 -06:00
refactor: name the listing options once
Eight places tested the five --list-* options by hand, and four lists named them. One table and one function now say which a run gave, so a sixth listing is one line.
This commit is contained in:
1 parent
9a27d0b574
commit
8ecd102c77
8 files changed
+66
-61
No files matched your search
+23
-25
@@ -545,6 +545,18 @@ _COMMAND_ORDER = (
|
||||
)
|
||||
|
||||
|
||||
# The options that print a list and install nothing, in the order a run
|
||||
# names them.
|
||||
LISTING_FLAGS = (("--list-platforms", "list_platforms"), ("--list-targets", "list_targets"),
|
||||
("--list-systems", "list_systems"), ("--list-cores", "list_cores"),
|
||||
("--list-emulators", "list_emulators"))
|
||||
|
||||
|
||||
def listings_given(args: argparse.Namespace) -> list[str]:
|
||||
"""The listing options of a run, as typed."""
|
||||
return [flag for flag, attr in LISTING_FLAGS if getattr(args, attr)]
|
||||
|
||||
|
||||
def _command_rank(option: tuple[str, str | None]) -> int:
|
||||
flag = option[0]
|
||||
return _COMMAND_ORDER.index(flag) if flag in _COMMAND_ORDER else len(_COMMAND_ORDER)
|
||||
@@ -1549,8 +1561,7 @@ def _event_mode(args: argparse.Namespace) -> str:
|
||||
return "check"
|
||||
if args.dry_run:
|
||||
return "dry-run"
|
||||
if (args.list_platforms or args.list_targets or args.list_systems
|
||||
or args.list_cores or args.list_emulators):
|
||||
if listings_given(args):
|
||||
return "list"
|
||||
return "install"
|
||||
|
||||
@@ -13124,9 +13135,8 @@ def _tui_flag_blocker(args: argparse.Namespace) -> str:
|
||||
"""The option of a run without questions, said as the reason."""
|
||||
for flag, given in (
|
||||
("--check", args.check), ("--dry-run", args.dry_run),
|
||||
("--list-platforms", args.list_platforms), ("--list-targets", args.list_targets),
|
||||
("--list-systems", args.list_systems), ("--list-cores", args.list_cores),
|
||||
("--list-emulators", args.list_emulators), ("--events", args.events),
|
||||
*((flag, getattr(args, attr)) for flag, attr in LISTING_FLAGS),
|
||||
("--events", args.events),
|
||||
("--quiet", args.quiet), ("--yes", args.yes), ("--no-input", args.no_input),
|
||||
("--restore", args.restore is not None),
|
||||
("--pack", getattr(args, "pack", None) is not None),
|
||||
@@ -31402,8 +31412,7 @@ def _check_expert(parser: argparse.ArgumentParser, args: argparse.Namespace) ->
|
||||
"""--one-per-slot, --standalone, --source truth and --find, applied or
|
||||
refused, never ignored. Each is held equal to the pack builder's own
|
||||
option, so a choice the builder refuses beside it is refused here."""
|
||||
listing = (args.list_platforms or args.list_targets or args.list_systems
|
||||
or args.list_cores or args.list_emulators)
|
||||
listing = bool(listings_given(args))
|
||||
truth = args.source == "truth"
|
||||
refusals = (
|
||||
(args.json and not args.find, "--json applies to --find"),
|
||||
@@ -31498,8 +31507,7 @@ def _main_check_values(parser: argparse.ArgumentParser, args: argparse.Namespace
|
||||
):
|
||||
parser.error(f"{option} needs at least one name")
|
||||
if args.quiet and (
|
||||
args.check or args.dry_run or args.list_platforms or args.list_targets
|
||||
or args.list_systems or args.list_cores or args.list_emulators
|
||||
args.check or args.dry_run or listings_given(args)
|
||||
):
|
||||
parser.error("--quiet applies to an install, not to --check, --dry-run or a listing")
|
||||
if args.tui and args.plain:
|
||||
@@ -31509,9 +31517,7 @@ def _main_check_values(parser: argparse.ArgumentParser, args: argparse.Namespace
|
||||
if args.required_only and args.for_games is None:
|
||||
parser.error("--required-only applies to --for-games: the list alone does not "
|
||||
"say which files a game cannot start without")
|
||||
if args.for_games is not None and (
|
||||
args.list_platforms or args.list_targets or args.list_systems
|
||||
or args.list_cores or args.list_emulators):
|
||||
if args.for_games is not None and listings_given(args):
|
||||
parser.error("--for-games narrows an install, not a listing")
|
||||
|
||||
|
||||
@@ -31520,10 +31526,7 @@ def _main_check_listings(parser: argparse.ArgumentParser, args: argparse.Namespa
|
||||
# Applied or refused, never ignored: a run prints one list, and the
|
||||
# narrowing options apply to --list-systems and --list-cores only, past
|
||||
# --target and --installed-cores, which --list-emulators also reads.
|
||||
listings = [flag for flag, given in (
|
||||
("--list-platforms", args.list_platforms), ("--list-targets", args.list_targets),
|
||||
("--list-systems", args.list_systems), ("--list-cores", args.list_cores),
|
||||
("--list-emulators", args.list_emulators)) if given]
|
||||
listings = listings_given(args)
|
||||
if len(listings) > 1:
|
||||
parser.error(f"{listings[0]} and {listings[1]} each print a list: run them "
|
||||
"one at a time")
|
||||
@@ -31573,8 +31576,7 @@ def _main_check_add_app(parser: argparse.ArgumentParser, args: argparse.Namespac
|
||||
(args.check or args.dry_run,
|
||||
"--add-app writes the RetroBIOS app on the card, which --check and "
|
||||
"--dry-run do not"),
|
||||
(args.list_platforms or args.list_targets or args.list_systems
|
||||
or args.list_cores or args.list_emulators,
|
||||
(listings_given(args),
|
||||
"--add-app writes the RetroBIOS app on the card, which a listing does not"),
|
||||
(args.from_pack, "--add-app downloads the RetroBIOS app, and --from-pack "
|
||||
"makes no network request"),
|
||||
@@ -31607,10 +31609,7 @@ def _main_check_offline(parser: argparse.ArgumentParser, args: argparse.Namespac
|
||||
|
||||
def _main_check_sources(parser: argparse.ArgumentParser, args: argparse.Namespace) -> None:
|
||||
"""Refuse a source of files given with a listing that reads none."""
|
||||
if getattr(args, "from") and (
|
||||
args.list_platforms or args.list_targets or args.list_systems
|
||||
or args.list_cores or args.list_emulators
|
||||
):
|
||||
if getattr(args, "from") and listings_given(args):
|
||||
parser.error("--from copies files into the BIOS folder, which a listing "
|
||||
"does not write")
|
||||
if (args.from_pack or args.manifest) and args.list_platforms:
|
||||
@@ -31769,9 +31768,8 @@ def _check_pack(parser: argparse.ArgumentParser, args: argparse.Namespace) -> No
|
||||
("--installed-cores", args.installed_cores), ("--cores-dir", args.cores_dir),
|
||||
("--save-dir", args.save_dir), ("--standalone-copies", args.standalone_copies),
|
||||
("--add-app", args.add_app), ("--romm-firmware", args.romm_firmware is not None),
|
||||
("--tui", args.tui), ("--list-platforms", args.list_platforms),
|
||||
("--list-targets", args.list_targets), ("--list-systems", args.list_systems),
|
||||
("--list-cores", args.list_cores), ("--list-emulators", args.list_emulators),
|
||||
("--tui", args.tui),
|
||||
*((flag, getattr(args, attr)) for flag, attr in LISTING_FLAGS),
|
||||
):
|
||||
if given:
|
||||
parser.error(f"--pack writes a pack ZIP, and {flag} reads or writes the "
|
||||
|
||||
Reference in new issue
Block a user