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:
Abdessamad Derraz committed 2026-11-21 06:04:39 +01:00
1 parent 9a27d0b574
commit 8ecd102c77
8 files changed
+66 -61

No files matched your search

+1 -1
View File
@@ -16,7 +16,7 @@
# and Invoke-WebRequest throws on a cut transfer before the hash is read:
# the site's build rewrites this line there (scripts/sitebootstrap.py).
$mismatchAdvice = "The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
$defaultInstallSha256 = "51a8d68a168a7cda89969c568aa1342202af26140e906af0105f44fa413d0cd1"
$defaultInstallSha256 = "fe4bc003ca129ff7c5f3adf622b51fded3c223560e7bf3a0e0c3289b7f9d706d"
# The pin above refuses any changed byte: this cap only stops a body that
# cannot be the installer (a sign-in portal's page) before it is hashed.
$maximumInstallerBytes = 8MB
+23 -25
View File
@@ -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 "
+1 -1
View File
@@ -23,7 +23,7 @@ DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/ins
# curl or wget stop on a cut transfer before the hash is read: the site's
# build rewrites this line there (scripts/sitebootstrap.py).
MISMATCH_ADVICE="The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
DEFAULT_INSTALL_SHA256="51a8d68a168a7cda89969c568aa1342202af26140e906af0105f44fa413d0cd1"
DEFAULT_INSTALL_SHA256="fe4bc003ca129ff7c5f3adf622b51fded3c223560e7bf3a0e0c3289b7f9d706d"
# The pin above refuses any changed byte: this cap only stops a body that
# cannot be the installer (a sign-in portal's page) before it is hashed.
MAX_INSTALLER_BYTES=8388608
+8 -8
View File
@@ -27,8 +27,8 @@
{
"dest": "roms/ports/retrobios/install.py",
"repo_path": "install.py",
"size": 1449198,
"sha256": "51a8d68a168a7cda89969c568aa1342202af26140e906af0105f44fa413d0cd1",
"size": 1448585,
"sha256": "fe4bc003ca129ff7c5f3adf622b51fded3c223560e7bf3a0e0c3289b7f9d706d",
"executable": false
},
{
@@ -71,8 +71,8 @@
"muos": {
"archive": {
"dest": "ARCHIVE/RetroBIOS.muxapp",
"size": 1502823,
"sha256": "a89d78536fbb9c9642f57a879b7895f1d01607c57f781cdeeccaa54851db205f"
"size": 1502210,
"sha256": "a67944ee5000e3b1fc22081e0062025789b5d7b5efd25446df11bedbd04b0920"
},
"members": [
{
@@ -92,8 +92,8 @@
{
"name": "RetroBIOS/install.py",
"repo_path": "install.py",
"size": 1449198,
"sha256": "51a8d68a168a7cda89969c568aa1342202af26140e906af0105f44fa413d0cd1",
"size": 1448585,
"sha256": "fe4bc003ca129ff7c5f3adf622b51fded3c223560e7bf3a0e0c3289b7f9d706d",
"executable": false
},
{
@@ -166,8 +166,8 @@
{
"dest": ".config/modules/retrobios/install.py",
"repo_path": "install.py",
"size": 1449198,
"sha256": "51a8d68a168a7cda89969c568aa1342202af26140e906af0105f44fa413d0cd1",
"size": 1448585,
"sha256": "fe4bc003ca129ff7c5f3adf622b51fded3c223560e7bf3a0e0c3289b7f9d706d",
"executable": false
},
{
+16 -21
View File
@@ -18,7 +18,14 @@ from installer.from_folders import _open_local_sources
from installer.handheld_app import app_not_added
from installer.host_fs import _is_dir, _writing
from installer.install_record import restore_kept
from installer.invocation import OFFLINE_VARIABLE, _INVOCATION, installer_id, offline_requested
from installer.invocation import (
LISTING_FLAGS,
OFFLINE_VARIABLE,
_INVOCATION,
installer_id,
listings_given,
offline_requested,
)
from installer.narrowing import FIND_KINDS
from installer.network import _RAW_ERRORS, install_bounded_opener
from installer.offline import LOCAL, OFFLINE_FLAG_VALUE, offline_named
@@ -34,8 +41,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"),
@@ -130,8 +136,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:
@@ -141,9 +146,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")
@@ -152,10 +155,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")
@@ -205,8 +205,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"),
@@ -239,10 +238,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:
@@ -401,9 +397,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 "
+2 -2
View File
@@ -6,6 +6,7 @@ import json
import threading
from typing import TextIO
from installer.invocation import listings_given
from installer.text import _CONTROLS
EVENT_KEYS: dict[str, tuple[str, ...]] = {
@@ -220,8 +221,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"
+12
View File
@@ -35,6 +35,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)
+3 -3
View File
@@ -9,6 +9,7 @@ import sys
from collections.abc import Mapping
from typing import TYPE_CHECKING, NamedTuple, TextIO
from installer.invocation import LISTING_FLAGS
from installer.terminal import TUI_MIN_COLS, TUI_MIN_ROWS, _enable_ansi, terminal_few_colours, terminal_without_ansi
from installer.text import screen_text
@@ -194,9 +195,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),