cli: make some functions only create commits optionally
This commit is contained in:
@@ -522,7 +522,9 @@ def get_inventory_with_writeable_keys(
|
|||||||
|
|
||||||
|
|
||||||
@API.register
|
@API.register
|
||||||
def set_inventory(inventory: Inventory, flake_dir: str | Path, message: str) -> None:
|
def set_inventory(
|
||||||
|
inventory: Inventory, flake_dir: str | Path, message: str, commit: bool = True
|
||||||
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Write the inventory to the flake directory
|
Write the inventory to the flake directory
|
||||||
and commit it to git with the given message
|
and commit it to git with the given message
|
||||||
@@ -553,6 +555,7 @@ def set_inventory(inventory: Inventory, flake_dir: str | Path, message: str) ->
|
|||||||
with inventory_file.open("w") as f:
|
with inventory_file.open("w") as f:
|
||||||
json.dump(persisted, f, indent=2)
|
json.dump(persisted, f, indent=2)
|
||||||
|
|
||||||
|
if commit:
|
||||||
commit_file(inventory_file, Path(flake_dir), commit_message=message)
|
commit_file(inventory_file, Path(flake_dir), commit_message=message)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class CreateOptions:
|
|||||||
|
|
||||||
|
|
||||||
@API.register
|
@API.register
|
||||||
def create_machine(opts: CreateOptions) -> None:
|
def create_machine(opts: CreateOptions, commit: bool = True) -> None:
|
||||||
if not opts.clan_dir.is_local:
|
if not opts.clan_dir.is_local:
|
||||||
msg = f"Clan {opts.clan_dir} is not a local clan."
|
msg = f"Clan {opts.clan_dir} is not a local clan."
|
||||||
description = "Import machine only works on local clans"
|
description = "Import machine only works on local clans"
|
||||||
@@ -115,6 +115,7 @@ def create_machine(opts: CreateOptions) -> None:
|
|||||||
# Commit at the end in that order to avoid committing halve-baked machines
|
# Commit at the end in that order to avoid committing halve-baked machines
|
||||||
# TODO: automatic rollbacks if something goes wrong
|
# TODO: automatic rollbacks if something goes wrong
|
||||||
|
|
||||||
|
if commit:
|
||||||
commit_file(
|
commit_file(
|
||||||
clan_dir / "machines" / machine_name,
|
clan_dir / "machines" / machine_name,
|
||||||
repo_dir=clan_dir,
|
repo_dir=clan_dir,
|
||||||
|
|||||||
Reference in New Issue
Block a user