clan-cli: add CLAN_DIR environment variable
Add the `CLAN_DIR` environment variable. With this the user can specify the location of the clan.
This commit is contained in:
@@ -19,7 +19,7 @@ from . import (
|
|||||||
vms,
|
vms,
|
||||||
)
|
)
|
||||||
from .custom_logger import setup_logging
|
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 .errors import ClanCmdError, ClanError
|
||||||
from .profiler import profile
|
from .profiler import profile
|
||||||
from .ssh import cli as ssh_cli
|
from .ssh import cli as ssh_cli
|
||||||
@@ -77,8 +77,8 @@ def create_parser(prog: str | None = None) -> argparse.ArgumentParser:
|
|||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--flake",
|
"--flake",
|
||||||
help="path to the flake where the clan resides in, can be a remote flake or local",
|
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(),
|
default=get_clan_flake_toplevel_or_env(),
|
||||||
type=flake_path,
|
type=flake_path,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,12 @@ from pathlib import Path
|
|||||||
log = logging.getLogger(__name__)
|
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:
|
def get_clan_flake_toplevel() -> Path | None:
|
||||||
return find_toplevel([".clan-flake", ".git", ".hg", ".svn", "flake.nix"])
|
return find_toplevel([".clan-flake", ".git", ".hg", ".svn", "flake.nix"])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user