From f383c6f82dd342eb6b21ea34951cd1519c7e81e1 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Tue, 30 Apr 2024 12:00:47 +0200 Subject: [PATCH] clan-cli: add `CLAN_DIR` environment variable Add the `CLAN_DIR` environment variable. With this the user can specify the location of the clan. --- pkgs/clan-cli/clan_cli/__init__.py | 6 +++--- pkgs/clan-cli/clan_cli/dirs.py | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/__init__.py b/pkgs/clan-cli/clan_cli/__init__.py index 7e1b9280..b6c60ffd 100644 --- a/pkgs/clan-cli/clan_cli/__init__.py +++ b/pkgs/clan-cli/clan_cli/__init__.py @@ -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, ) diff --git a/pkgs/clan-cli/clan_cli/dirs.py b/pkgs/clan-cli/clan_cli/dirs.py index abcf8325..9b687aa4 100644 --- a/pkgs/clan-cli/clan_cli/dirs.py +++ b/pkgs/clan-cli/clan_cli/dirs.py @@ -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"]) -- 2.45.2