diff --git a/pkgs/clan-cli/clan_cli/clan/create.py b/pkgs/clan-cli/clan_cli/clan/create.py index 698b36906..8d224474a 100644 --- a/pkgs/clan-cli/clan_cli/clan/create.py +++ b/pkgs/clan-cli/clan_cli/clan/create.py @@ -6,7 +6,7 @@ from pathlib import Path from clan_cli.api import API from clan_cli.cmd import CmdOut, run -from clan_cli.dirs import clan_templates +from clan_cli.dirs import TemplateType, clan_templates from clan_cli.errors import ClanError from clan_cli.inventory import Inventory, init_inventory from clan_cli.nix import nix_command, nix_shell @@ -38,7 +38,7 @@ def git_command(directory: Path, *args: str) -> list[str]: @API.register def create_clan(options: CreateOptions) -> CreateClanResponse: directory = Path(options.directory).resolve() - template_url = f"{clan_templates()}#{options.template}" + template_url = f"{clan_templates(TemplateType.CLAN)}#{options.template}" if not directory.exists(): directory.mkdir() else: diff --git a/pkgs/clan-cli/clan_cli/dirs.py b/pkgs/clan-cli/clan_cli/dirs.py index a39f64044..09b777727 100644 --- a/pkgs/clan-cli/clan_cli/dirs.py +++ b/pkgs/clan-cli/clan_cli/dirs.py @@ -2,6 +2,7 @@ import logging import os import sys import urllib +from enum import Enum from pathlib import Path from clan_cli.clan_uri import FlakeId @@ -45,11 +46,17 @@ def find_toplevel(top_level_files: list[str]) -> Path | None: return None -def clan_templates() -> Path: - template_path = module_root().parent.parent.parent / "templates" +class TemplateType(Enum): + CLAN = "clan" + + +def clan_templates(template_type: TemplateType) -> Path: + template_path = ( + module_root().parent.parent.parent / "templates" / template_type.value + ) if template_path.exists(): return template_path - template_path = module_root() / "templates" + template_path = module_root() / "templates" / template_type.value if not template_path.exists(): msg = f"BUG! clan core not found at {template_path}. This is an issue with packaging the cli" raise ClanError(msg) diff --git a/pkgs/clan-cli/clan_cli/machines/create.py b/pkgs/clan-cli/clan_cli/machines/create.py index fc73cac93..3c95d9fa3 100644 --- a/pkgs/clan-cli/clan_cli/machines/create.py +++ b/pkgs/clan-cli/clan_cli/machines/create.py @@ -11,7 +11,7 @@ from clan_cli.clan.create import git_command from clan_cli.clan_uri import FlakeId from clan_cli.cmd import Log, run from clan_cli.completions import add_dynamic_completer, complete_tags -from clan_cli.dirs import clan_templates, get_clan_flake_toplevel_or_env +from clan_cli.dirs import TemplateType, clan_templates, get_clan_flake_toplevel_or_env from clan_cli.errors import ClanError from clan_cli.inventory import Machine as InventoryMachine from clan_cli.inventory import ( @@ -56,7 +56,7 @@ def create_machine(opts: CreateOptions) -> None: raise ClanError(msg, description=description) if not opts.template_src: - opts.template_src = FlakeId(str(clan_templates())) + opts.template_src = FlakeId(str(clan_templates(TemplateType.CLAN))) if not opts.template_name: opts.template_name = "new-machine"