cli machines update: find flake dir automatic if not provided, support flake as path
This commit is contained in:
parent
06aaa35119
commit
c9d7a96844
@ -2,6 +2,7 @@ import logging
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from .errors import ClanError
|
||||
from .types import FlakeName
|
||||
@ -9,27 +10,27 @@ from .types import FlakeName
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# def _get_clan_flake_toplevel() -> Path:
|
||||
# return find_toplevel([".clan-flake", ".git", ".hg", ".svn", "flake.nix"])
|
||||
def get_clan_flake_toplevel() -> Path:
|
||||
return find_toplevel([".clan-flake", ".git", ".hg", ".svn", "flake.nix"])
|
||||
|
||||
|
||||
# def find_git_repo_root() -> Optional[Path]:
|
||||
# try:
|
||||
# return find_toplevel([".git"])
|
||||
# except ClanError:
|
||||
# return None
|
||||
def find_git_repo_root() -> Optional[Path]:
|
||||
try:
|
||||
return find_toplevel([".git"])
|
||||
except ClanError:
|
||||
return None
|
||||
|
||||
|
||||
# def find_toplevel(top_level_files: list[str]) -> Path:
|
||||
# """Returns the path to the toplevel of the clan flake"""
|
||||
# for project_file in top_level_files:
|
||||
# initial_path = Path(os.getcwd())
|
||||
# path = Path(initial_path)
|
||||
# while path.parent != path:
|
||||
# if (path / project_file).exists():
|
||||
# return path
|
||||
# path = path.parent
|
||||
# raise ClanError("Could not find clan flake toplevel directory")
|
||||
def find_toplevel(top_level_files: list[str]) -> Path:
|
||||
"""Returns the path to the toplevel of the clan flake"""
|
||||
for project_file in top_level_files:
|
||||
initial_path = Path(os.getcwd())
|
||||
path = Path(initial_path)
|
||||
while path.parent != path:
|
||||
if (path / project_file).exists():
|
||||
return path
|
||||
path = path.parent
|
||||
raise ClanError("Could not find clan flake toplevel directory")
|
||||
|
||||
|
||||
def user_config_dir() -> Path:
|
||||
|
@ -4,7 +4,7 @@ import os
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from ..dirs import specific_flake_dir
|
||||
from ..dirs import get_clan_flake_toplevel
|
||||
from ..machines.machines import Machine
|
||||
from ..nix import nix_build, nix_command, nix_config
|
||||
from ..secrets.generate import generate_secrets
|
||||
@ -116,7 +116,10 @@ def get_selected_machines(machine_names: list[str], flake_dir: Path) -> HostGrou
|
||||
|
||||
# FIXME: we want some kind of inventory here.
|
||||
def update(args: argparse.Namespace) -> None:
|
||||
flake_dir = specific_flake_dir(args.flake)
|
||||
if args.flake is None:
|
||||
flake_dir = get_clan_flake_toplevel()
|
||||
else:
|
||||
flake_dir = args.flake
|
||||
if len(args.machines) == 1 and args.target_host is not None:
|
||||
machine = Machine(name=args.machines[0], flake_dir=flake_dir)
|
||||
machine.deployment_address = args.target_host
|
||||
@ -148,9 +151,10 @@ def register_update_parser(parser: argparse.ArgumentParser) -> None:
|
||||
default=[],
|
||||
)
|
||||
parser.add_argument(
|
||||
"flake",
|
||||
"--flake",
|
||||
type=str,
|
||||
help="name of the flake to update machine for",
|
||||
default=None,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--target-host",
|
||||
|
Loading…
Reference in New Issue
Block a user