1
0
forked from clan/clan-core

Added better error handling in --flake argument

This commit is contained in:
Luis Hebendanz 2023-12-01 15:45:05 +01:00
parent f9b7c5a468
commit 3db73d3396
3 changed files with 26 additions and 1 deletions

View File

@ -10,6 +10,7 @@ from . import config, flakes, machines, secrets, vms, webui
from .custom_logger import setup_logging
from .dirs import get_clan_flake_toplevel
from .ssh import cli as ssh_cli
from .dirs import is_clan_flake
log = logging.getLogger(__name__)
@ -56,11 +57,21 @@ def create_parser(prog: str | None = None) -> argparse.ArgumentParser:
default=[],
)
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")
if not flake_dir.is_dir():
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")
return flake_dir
parser.add_argument(
"--flake",
help="path to the flake where the clan resides in",
default=get_clan_flake_toplevel(),
type=Path,
type=flake_path,
)
subparsers = parser.add_subparsers()

View File

@ -9,6 +9,9 @@ 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()
def find_git_repo_root() -> Path | None:
return find_toplevel([".git"])

View File

@ -0,0 +1,11 @@
{
"folders": [
{
"path": ".."
},
{
"path": "../../clan-cli"
}
],
"settings": {}
}