b31fdd023a
Product / UI / CLI / docs rebrand. Internal package, repo, and on-disk dir names stay 'cloud_sync' / 'cloud-sync' / '.cloud-sync/' to avoid breaking existing installs; a future commit can do the file-system rename when the cost is worth paying. User-facing changes: CLI prog name: cloud-sync -> instance-sync CLI description: cloud-svc URL -> Timemachine Network endpoint Dialog title: CLOUD SYNC -> INSTANCE SYNC Dialog title: CLOUD CONFLICT -> INSTANCE CONFLICT Dialog title: CONNECT CLOUD SAVE -> CONNECT TO THE NETWORK Card label: Cloud Save -> Remote Save Skip button: Skip cloud sync -> Skip instance sync Body copy: 'the cloud' -> 'the Timemachine Network' Window titles: Cloud sync — ... -> Instance sync — ... Log prefix: cloud-sync: -> instance-sync: Error prose: 'cloud-sync token' -> 'instance-sync token' Backend changes: restic --host tag: cloud-sync -> instance-sync State.host_tag dflt: cloud-sync -> instance-sync (Existing snapshots with the old tag still pull fine; we use 'latest'.) Drop tkinter fallback: ui.py now offers Qt OR Headless. tkinter is unnecessary given we already maintain Qt + headless; one less code path to keep styled, smaller pyz. make_progress() picks Qt first, falls through to HeadlessProgress on ImportError with a stderr hint to 'pip install PySide6'. README: rebrand title + prose; note repo/dir rename deferred; call out the PySide6 install step. Conflict/login dialogs are now Qt-only; without Qt, conflict aborts (defensive) and login tells the user to paste the token manually. 52 tests green; no test-file label changes needed since they only exercise internal APIs.
106 lines
3.5 KiB
Python
106 lines
3.5 KiB
Python
"""CLI parsing + entry point dispatch.
|
|
|
|
Flag style mirrors packwiz-installer-bootstrap so operators wiring Prism's
|
|
PreLaunch/PostExit hooks don't relearn the surface. Supports both
|
|
``--url value`` and ``--url=value`` forms.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import sys
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Args:
|
|
"""Parsed CLI args shared by both pull + push subcommands."""
|
|
|
|
url: str
|
|
pack_folder: Path
|
|
token_file: Path
|
|
restic_binary: Path | None # None → auto-discover
|
|
allow_download: bool
|
|
headless: bool
|
|
|
|
|
|
def build_parser() -> argparse.ArgumentParser:
|
|
p = argparse.ArgumentParser(
|
|
prog="instance-sync",
|
|
description="Per-user Minecraft instance sync via the Timemachine Network.",
|
|
)
|
|
p.add_argument("--version", action="version", version="instance-sync 0.1.0")
|
|
|
|
sub = p.add_subparsers(dest="cmd", required=True)
|
|
for name in ("pull", "push"):
|
|
sp = sub.add_parser(name, help=f"{name} instance state")
|
|
sp.add_argument(
|
|
"--url", required=True,
|
|
help="Timemachine Network endpoint (e.g. https://cloud.tm.center)",
|
|
)
|
|
sp.add_argument(
|
|
"--pack-folder", default=".", type=Path,
|
|
help="Minecraft instance directory (default: cwd)",
|
|
)
|
|
sp.add_argument(
|
|
"--token-file", default=None, type=Path,
|
|
help="Token file path (default: <pack-folder>/.cloud-sync/token)",
|
|
)
|
|
sp.add_argument(
|
|
"--restic-binary", default=None, type=Path,
|
|
help="Path to a restic binary; overrides auto-discovery",
|
|
)
|
|
sp.add_argument(
|
|
"--no-download", action="store_true",
|
|
help="Don't auto-fetch restic from upstream; fail if not found locally",
|
|
)
|
|
sp.add_argument(
|
|
"-g", "--no-gui", action="store_true",
|
|
help="Headless mode (no Qt windows; status to stdout only)",
|
|
)
|
|
return p
|
|
|
|
|
|
def parse(argv: list[str]) -> tuple[str, Args]:
|
|
"""Parse argv → (subcommand, Args). Raises SystemExit on error/help."""
|
|
ns = build_parser().parse_args(argv)
|
|
pack = Path(ns.pack_folder).absolute().resolve()
|
|
token = (
|
|
Path(ns.token_file).absolute()
|
|
if ns.token_file is not None
|
|
else pack / ".cloud-sync" / "token"
|
|
)
|
|
return ns.cmd, Args(
|
|
url=ns.url,
|
|
pack_folder=pack,
|
|
token_file=token,
|
|
restic_binary=Path(ns.restic_binary).absolute() if ns.restic_binary else None,
|
|
allow_download=not ns.no_download,
|
|
headless=ns.no_gui,
|
|
)
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> int:
|
|
"""CLI entrypoint. Returns exit code (0=ok, 1=user cancel, 2=error)."""
|
|
# Imports kept here so tests of parse() don't drag UI in.
|
|
from . import sync, ui
|
|
|
|
try:
|
|
cmd, args = parse(sys.argv[1:] if argv is None else argv)
|
|
except SystemExit as e:
|
|
return int(e.code) if isinstance(e.code, int) else 2
|
|
|
|
action = {"pull": sync.pull, "push": sync.push}[cmd]
|
|
progress = ui.make_progress(headless=args.headless)
|
|
title = "Instance sync — pulling" if cmd == "pull" else "Instance sync — pushing"
|
|
|
|
try:
|
|
return progress.run_with(lambda: action(args, progress), title)
|
|
except KeyboardInterrupt:
|
|
print("instance-sync: cancelled", file=sys.stderr)
|
|
return 1
|
|
except Exception as e: # noqa: BLE001
|
|
print(f"instance-sync {cmd}: {e}", file=sys.stderr)
|
|
return 2
|