Simplify plugin-helper state configuration

This commit is contained in:
pleb
2026-07-01 13:43:39 -07:00
parent 1be1353835
commit 407abfe6ec
6 changed files with 213 additions and 199 deletions
+10 -51
View File
@@ -6,7 +6,7 @@ import sys
from pathlib import Path
from typing import Any
from .config import Profile, repo_root, resolve_runtime_config
from .config import repo_root, resolve_runtime_config
from .bootstrap import run_bootstrap
from .bsipa import check_bsipa_health
from .checker import check_lock
@@ -63,8 +63,6 @@ def _add_common(parser: argparse.ArgumentParser, *, suppress_default: bool = Fal
default = argparse.SUPPRESS if suppress_default else None
parser.add_argument("--instances-root", default=default, help="BSManager instances root")
parser.add_argument("--state-dir", default=default, help="plugin-helper state directory")
parser.add_argument("--profile", default=default, help="Configured profile id from plugin-helper.local.toml")
parser.add_argument("--config", default=default, help="Path to plugin-helper TOML config")
def build_parser() -> argparse.ArgumentParser:
@@ -225,37 +223,6 @@ def _common_parent() -> argparse.ArgumentParser:
return parent
def _menu_profiles(
*,
profiles: tuple[Profile, ...],
selected_profile: Profile | None,
instances_roots: list[Path],
state_root: Path,
use_config_profiles: bool,
) -> list[Profile]:
if selected_profile:
return [
Profile(
id=selected_profile.id if len(instances_roots) == 1 else f"{selected_profile.id}-{index}",
label=selected_profile.label,
instances_root=root,
state_dir=state_root,
)
for index, root in enumerate(instances_roots, start=1)
]
if use_config_profiles and profiles:
return list(profiles)
return [
Profile(
id=f"root-{index}",
label=str(root),
instances_root=root,
state_dir=state_root,
)
for index, root in enumerate(instances_roots, start=1)
]
def _run_menu(
*,
runtime: Any,
@@ -269,35 +236,29 @@ def _run_menu(
print("Install project dependencies, for example: python -m pip install -e .")
return 1
profiles = _menu_profiles(
profiles=runtime.profiles,
selected_profile=runtime.selected_profile,
instances_roots=runtime.instances_roots,
state_root=runtime.state_root,
use_config_profiles=runtime.config_loaded and not explicit_instances_root and not explicit_state_dir,
)
choices: list[InstallationChoice] = []
for profile in profiles:
for instance in list_instances(profile.instances_root):
for index, root in enumerate(runtime.instances_roots, start=1):
install_label = str(root) if len(runtime.instances_roots) > 1 else "Default"
for instance in list_instances(root):
choices.append(
InstallationChoice(
profile_id=profile.id,
profile_label=profile.label,
install_id=f"root-{index}",
install_label=install_label,
instance_name=instance.name,
instance_path=instance.path,
state_root=profile.state_dir,
state_root=runtime.state_root,
)
)
if not choices:
searched = ", ".join(str(profile.instances_root) for profile in profiles)
searched = ", ".join(str(root) for root in runtime.instances_roots)
print(f"No Beat Saber instances found under {searched}")
return 1
setup_hint = None
if not runtime.config_loaded and not runtime.selected_profile and not explicit_instances_root and not explicit_state_dir:
if not runtime.config_loaded and not explicit_instances_root and not explicit_state_dir:
setup_hint = (
f"No {runtime.config_path.name} found; using default roots and default state. "
f"Copy plugin-helper.toml.example to {runtime.config_path.name} to map each install to a state dir."
f"Copy plugin-helper.toml.example to {runtime.config_path.name} to set a custom state dir."
)
app = PluginHelperTui(choices=choices, repo_root=repo_root(), setup_hint=setup_hint)
result = app.run()
@@ -321,8 +282,6 @@ def run(argv: list[str] | None = None) -> int:
runtime = resolve_runtime_config(
instances_root_value=getattr(args, "instances_root", None),
state_dir_value=getattr(args, "state_dir", None),
profile_id=getattr(args, "profile", None),
config_path=getattr(args, "config", None),
)
inst_roots = runtime.instances_roots
st_root = runtime.state_root