Clan create: migrate to inventory
This commit is contained in:
@@ -1,35 +1,20 @@
|
||||
import json
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from clan_cli.api import API
|
||||
from clan_cli.clan.create import ClanMetaInfo
|
||||
from clan_cli.errors import ClanError
|
||||
from clan_cli.inventory import Inventory, InventoryMeta
|
||||
|
||||
|
||||
@dataclass
|
||||
class UpdateOptions:
|
||||
directory: str
|
||||
meta: ClanMetaInfo | None = None
|
||||
meta: InventoryMeta
|
||||
|
||||
|
||||
@API.register
|
||||
def update_clan_meta(options: UpdateOptions) -> ClanMetaInfo:
|
||||
meta_file = Path(options.directory) / Path("clan/meta.json")
|
||||
if not meta_file.exists():
|
||||
raise ClanError(
|
||||
"File not found",
|
||||
description=f"Could not find {meta_file} to update.",
|
||||
location="update_clan_meta",
|
||||
)
|
||||
def update_clan_meta(options: UpdateOptions) -> InventoryMeta:
|
||||
inventory = Inventory.load_file(options.directory)
|
||||
inventory.meta = options.meta
|
||||
|
||||
meta_content: dict[str, str] = {}
|
||||
with open(meta_file) as f:
|
||||
meta_content = json.load(f)
|
||||
inventory.persist(options.directory, "Update clan meta")
|
||||
|
||||
meta_content = {**meta_content, **options.meta.__dict__}
|
||||
|
||||
with open(meta_file) as f:
|
||||
json.dump(meta_content, f)
|
||||
|
||||
return ClanMetaInfo(**meta_content)
|
||||
return inventory.meta
|
||||
|
||||
Reference in New Issue
Block a user