refactor(cli/inventory): remove unncessary init_inventory function
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user