Refactor: replace direct references to inventory

Deprecated. Inventory should be accessed via InventoryStore {read(),write(),...}
This commit is contained in:
Johannes Kirschbauer
2025-05-16 11:30:41 +02:00
parent 13fa74b8cd
commit c43d8fa958
6 changed files with 37 additions and 27 deletions

View File

@@ -6,11 +6,11 @@ from pathlib import Path
from clan_lib.api import API
from clan_lib.nix_models.inventory import Inventory
from clan_lib.persist.inventory_store import InventoryStore
from clan_cli.cmd import CmdOut, RunOpts, run
from clan_cli.errors import ClanError
from clan_cli.flake import Flake
from clan_cli.inventory import set_inventory
from clan_cli.nix import nix_command, nix_metadata, nix_shell
from clan_cli.templates import (
InputPrio,
@@ -108,11 +108,8 @@ def create_clan(opts: CreateOptions) -> CreateClanResponse:
response.flake_update = flake_update
if opts.initial:
set_inventory(
flake=Flake(str(opts.dest)),
inventory=opts.initial,
message="Init inventory",
)
inventory_store = InventoryStore(flake=Flake(str(opts.dest)))
inventory_store.write(opts.initial, message="Init inventory")
return response

View File

@@ -2,9 +2,10 @@ from dataclasses import dataclass
from clan_lib.api import API
from clan_lib.nix_models.inventory import Inventory, Meta
from clan_lib.persist.inventory_store import InventoryStore
from clan_lib.persist.util import apply_patch
from clan_cli.flake import Flake
from clan_cli.inventory import load_inventory_json, set_inventory
@dataclass
@@ -15,9 +16,9 @@ class UpdateOptions:
@API.register
def update_clan_meta(options: UpdateOptions) -> Inventory:
inventory = load_inventory_json(options.flake)
inventory["meta"] = options.meta
set_inventory(inventory, options.flake, "Update clan metadata")
inventory_store = InventoryStore(options.flake)
inventory = inventory_store.read()
apply_patch(inventory, "meta", options.meta)
inventory_store.write(inventory, message="Update clan metadata")
return inventory