1
0
forked from clan/clan-core
This commit is contained in:
Luis Hebendanz 2023-12-01 15:46:27 +01:00
parent 3db73d3396
commit 583311fcda
2 changed files with 12 additions and 6 deletions

View File

@ -8,9 +8,8 @@ from typing import Any
from . import config, flakes, machines, secrets, vms, webui
from .custom_logger import setup_logging
from .dirs import get_clan_flake_toplevel
from .dirs import get_clan_flake_toplevel, is_clan_flake
from .ssh import cli as ssh_cli
from .dirs import is_clan_flake
log = logging.getLogger(__name__)
@ -57,14 +56,20 @@ def create_parser(prog: str | None = None) -> argparse.ArgumentParser:
default=[],
)
def flake_path(arg:str) -> Path:
def flake_path(arg: str) -> Path:
flake_dir = Path(arg).resolve()
if not flake_dir.exists():
raise argparse.ArgumentTypeError(f"flake directory {flake_dir} does not exist")
raise argparse.ArgumentTypeError(
f"flake directory {flake_dir} does not exist"
)
if not flake_dir.is_dir():
raise argparse.ArgumentTypeError(f"flake directory {flake_dir} is not a directory")
raise argparse.ArgumentTypeError(
f"flake directory {flake_dir} is not a directory"
)
if not is_clan_flake(flake_dir):
raise argparse.ArgumentTypeError(f"flake directory {flake_dir} is not a clan flake")
raise argparse.ArgumentTypeError(
f"flake directory {flake_dir} is not a clan flake"
)
return flake_dir
parser.add_argument(

View File

@ -9,6 +9,7 @@ log = logging.getLogger(__name__)
def get_clan_flake_toplevel() -> Path | None:
return find_toplevel([".clan-flake", ".git", ".hg", ".svn", "flake.nix"])
def is_clan_flake(path: Path) -> bool:
return (path / ".clan-flake").exists()