Merge pull request 'clan-cli: add CLAN_DIR environment variable' (#1283) from a-kenji-feat/clan-dir into main
All checks were successful
checks / checks (push) Successful in 43s
checks / checks-impure (push) Successful in 2m5s

This commit is contained in:
clan-bot 2024-04-30 10:08:13 +00:00
commit 3da4117702
2 changed files with 9 additions and 3 deletions

View File

@ -19,7 +19,7 @@ from . import (
vms,
)
from .custom_logger import setup_logging
from .dirs import get_clan_flake_toplevel
from .dirs import get_clan_flake_toplevel_or_env
from .errors import ClanCmdError, ClanError
from .profiler import profile
from .ssh import cli as ssh_cli
@ -77,8 +77,8 @@ def create_parser(prog: str | None = None) -> argparse.ArgumentParser:
parser.add_argument(
"--flake",
help="path to the flake where the clan resides in, can be a remote flake or local",
default=get_clan_flake_toplevel(),
help="path to the flake where the clan resides in, can be a remote flake or local, can be set through the [CLAN_DIR] environment variable",
default=get_clan_flake_toplevel_or_env(),
type=flake_path,
)

View File

@ -7,6 +7,12 @@ from pathlib import Path
log = logging.getLogger(__name__)
def get_clan_flake_toplevel_or_env() -> Path | None:
if clan_dir := os.environ.get("CLAN_DIR"):
return Path(clan_dir)
return get_clan_flake_toplevel()
def get_clan_flake_toplevel() -> Path | None:
return find_toplevel([".clan-flake", ".git", ".hg", ".svn", "flake.nix"])