refactor(cli/inventory): remove unncessary init_inventory function

This commit is contained in:
Johannes Kirschbauer
2025-05-14 10:34:07 +02:00
parent 8b5cfb48c1
commit f8540de48e
2 changed files with 7 additions and 20 deletions

View File

@@ -10,7 +10,7 @@ from clan_lib.nix_models.inventory import Inventory
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 init_inventory
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,7 +108,11 @@ def create_clan(opts: CreateOptions) -> CreateClanResponse:
response.flake_update = flake_update
if opts.initial:
init_inventory(Flake(str(opts.dest)), init=opts.initial)
set_inventory(
flake=Flake(str(opts.dest)),
inventory=opts.initial,
message="Init inventory",
)
return response

View File

@@ -11,7 +11,6 @@ Which is an abstraction over the inventory
Interacting with 'clan_cli.inventory' is NOT recommended and will be removed
"""
import contextlib
import json
from collections import Counter
from dataclasses import dataclass
@@ -22,7 +21,7 @@ from clan_lib.api import API
from clan_lib.nix_models.inventory import Inventory
from clan_cli.cmd import run
from clan_cli.errors import ClanCmdError, ClanError
from clan_cli.errors import ClanError
from clan_cli.flake import Flake
from clan_cli.git import commit_file
from clan_cli.nix import nix_eval
@@ -560,22 +559,6 @@ def delete(flake: Flake, delete_set: set[str]) -> None:
)
def init_inventory(flake: Flake, init: Inventory | None = None) -> None:
inventory = None
# Try reading the current flake
if init is None:
with contextlib.suppress(ClanCmdError):
inventory = load_inventory_eval(flake)
if init is not None:
inventory = init
# Write inventory.json file
if inventory is not None:
# Persist creates a commit message for each change
set_inventory(inventory, flake, "Init inventory")
@API.register
def get_inventory(flake: Flake) -> Inventory:
return load_inventory_eval(flake)