feat: 'disable' renames to sync.json.disabled; new 'enable' rename-back
Pause/resume sync without losing the instance_id.
disable sync.json -> sync.json.disabled
enable sync.json.disabled -> sync.json
Re-enabling preserves the original ULID + url so the same restic
repo continues. No new instance_id minted, no orphaned snapshot
history. Tradeoff vs the previous 'disable = delete' semantics:
the on-disk artifact survives, so a truly fresh start now needs
'disable && rm sync.json.disabled' before 'setup'.
Implementation:
config.disable(pack) os.rename(sync.json -> sync.json.disabled).
False if no sync.json.
config.enable(pack) os.rename(sync.json.disabled -> sync.json).
Refuses if sync.json already exists
(caller must disable first).
config.delete(pack) now sweeps BOTH forms (escape hatch / tests).
setup_flow gains a precheck: if sync.json.disabled is present, point
the user at 'enable' instead of silently minting a fresh ULID over
their existing instance.
Opt-in gate (cfgmod.exists) is unchanged — only literal sync.json
counts. The .disabled sibling is invisible to pull/push, so the
silent-no-op behavior for paused instances Just Works.
cli adds 'enable' subcommand alongside 'disable'. _run_disable prints
'already disabled' when called twice; _run_enable refuses to clobber
an active config (exits 2 with the FileExistsError message).
7 new tests for disable/enable behavior + edge cases (idempotency,
nothing-to-X, refuse-clobber). 80 tests total.
This commit is contained in:
+49
-6
@@ -80,10 +80,22 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
help="discord_id:password token (read from stdin if omitted)",
|
||||
)
|
||||
|
||||
# --- disable: rm sync.json ---
|
||||
# --- disable: rename sync.json → sync.json.disabled ---
|
||||
sp = sub.add_parser(
|
||||
"disable",
|
||||
help="remove sync.json — re-noops the instance. Cloud data untouched.",
|
||||
help="pause sync on this instance (renames sync.json -> sync.json.disabled). "
|
||||
"Re-enable with `enable`. Cloud data untouched.",
|
||||
)
|
||||
sp.add_argument(
|
||||
"--pack-folder", default=".", type=Path,
|
||||
help="Minecraft instance directory (default: cwd)",
|
||||
)
|
||||
|
||||
# --- enable: rename sync.json.disabled → sync.json ---
|
||||
sp = sub.add_parser(
|
||||
"enable",
|
||||
help="resume sync on this instance (renames sync.json.disabled -> sync.json). "
|
||||
"Preserves the original instance_id + url so snapshots continue.",
|
||||
)
|
||||
sp.add_argument(
|
||||
"--pack-folder", default=".", type=Path,
|
||||
@@ -159,6 +171,8 @@ def main(argv: list[str] | None = None) -> int:
|
||||
|
||||
if cmd == "disable":
|
||||
return _run_disable(ns)
|
||||
if cmd == "enable":
|
||||
return _run_enable(ns)
|
||||
if cmd in ("setup", "init"):
|
||||
return _run_setup(ns, cmd)
|
||||
|
||||
@@ -186,13 +200,42 @@ def main(argv: list[str] | None = None) -> int:
|
||||
def _run_disable(ns: argparse.Namespace) -> int:
|
||||
from . import config as cfgmod
|
||||
pack = Path(ns.pack_folder).absolute().resolve()
|
||||
if cfgmod.delete(pack):
|
||||
print(f"instance-sync: removed {cfgmod.config_path(pack)}")
|
||||
else:
|
||||
print(f"instance-sync: no sync.json at {cfgmod.config_path(pack)} (already disabled)")
|
||||
if cfgmod.disable(pack):
|
||||
print(
|
||||
f"instance-sync: disabled — moved {cfgmod.config_path(pack).name} "
|
||||
f"to {cfgmod.disabled_path(pack).name} in {cfgmod.config_path(pack).parent}. "
|
||||
"Re-enable with `instance-sync enable`."
|
||||
)
|
||||
return 0
|
||||
if cfgmod.disabled_path(pack).exists():
|
||||
print(f"instance-sync: already disabled ({cfgmod.disabled_path(pack)} present)")
|
||||
return 0
|
||||
print(f"instance-sync: not enabled — no sync.json at {cfgmod.config_path(pack)}")
|
||||
return 0
|
||||
|
||||
|
||||
def _run_enable(ns: argparse.Namespace) -> int:
|
||||
from . import config as cfgmod
|
||||
pack = Path(ns.pack_folder).absolute().resolve()
|
||||
try:
|
||||
renamed = cfgmod.enable(pack)
|
||||
except FileExistsError as e:
|
||||
print(f"instance-sync: {e}", file=sys.stderr)
|
||||
return 2
|
||||
if renamed:
|
||||
print(f"instance-sync: enabled — restored {cfgmod.config_path(pack)}")
|
||||
return 0
|
||||
if cfgmod.config_path(pack).exists():
|
||||
print(f"instance-sync: already enabled ({cfgmod.config_path(pack)} present)")
|
||||
return 0
|
||||
print(
|
||||
f"instance-sync: no sync.json.disabled at {cfgmod.disabled_path(pack)}. "
|
||||
"Run `instance-sync setup` to opt in this instance fresh.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return 2
|
||||
|
||||
|
||||
def _run_setup(ns: argparse.Namespace, cmd: str) -> int:
|
||||
"""Wire `setup` (interactive) and `init` (flags-only) through the same
|
||||
flow module so both share the dialog/CLI logic."""
|
||||
|
||||
Reference in New Issue
Block a user