CLI: use new template path
This commit is contained in:
@@ -6,7 +6,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
from clan_cli.api import API
|
from clan_cli.api import API
|
||||||
from clan_cli.cmd import CmdOut, run
|
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.errors import ClanError
|
||||||
from clan_cli.inventory import Inventory, init_inventory
|
from clan_cli.inventory import Inventory, init_inventory
|
||||||
from clan_cli.nix import nix_command, nix_shell
|
from clan_cli.nix import nix_command, nix_shell
|
||||||
@@ -38,7 +38,7 @@ def git_command(directory: Path, *args: str) -> list[str]:
|
|||||||
@API.register
|
@API.register
|
||||||
def create_clan(options: CreateOptions) -> CreateClanResponse:
|
def create_clan(options: CreateOptions) -> CreateClanResponse:
|
||||||
directory = Path(options.directory).resolve()
|
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():
|
if not directory.exists():
|
||||||
directory.mkdir()
|
directory.mkdir()
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import urllib
|
import urllib
|
||||||
|
from enum import Enum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from clan_cli.clan_uri import FlakeId
|
from clan_cli.clan_uri import FlakeId
|
||||||
@@ -45,11 +46,17 @@ def find_toplevel(top_level_files: list[str]) -> Path | None:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def clan_templates() -> Path:
|
class TemplateType(Enum):
|
||||||
template_path = module_root().parent.parent.parent / "templates"
|
CLAN = "clan"
|
||||||
|
|
||||||
|
|
||||||
|
def clan_templates(template_type: TemplateType) -> Path:
|
||||||
|
template_path = (
|
||||||
|
module_root().parent.parent.parent / "templates" / template_type.value
|
||||||
|
)
|
||||||
if template_path.exists():
|
if template_path.exists():
|
||||||
return template_path
|
return template_path
|
||||||
template_path = module_root() / "templates"
|
template_path = module_root() / "templates" / template_type.value
|
||||||
if not template_path.exists():
|
if not template_path.exists():
|
||||||
msg = f"BUG! clan core not found at {template_path}. This is an issue with packaging the cli"
|
msg = f"BUG! clan core not found at {template_path}. This is an issue with packaging the cli"
|
||||||
raise ClanError(msg)
|
raise ClanError(msg)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from clan_cli.clan.create import git_command
|
|||||||
from clan_cli.clan_uri import FlakeId
|
from clan_cli.clan_uri import FlakeId
|
||||||
from clan_cli.cmd import Log, run
|
from clan_cli.cmd import Log, run
|
||||||
from clan_cli.completions import add_dynamic_completer, complete_tags
|
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.errors import ClanError
|
||||||
from clan_cli.inventory import Machine as InventoryMachine
|
from clan_cli.inventory import Machine as InventoryMachine
|
||||||
from clan_cli.inventory import (
|
from clan_cli.inventory import (
|
||||||
@@ -56,7 +56,7 @@ def create_machine(opts: CreateOptions) -> None:
|
|||||||
raise ClanError(msg, description=description)
|
raise ClanError(msg, description=description)
|
||||||
|
|
||||||
if not opts.template_src:
|
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:
|
if not opts.template_name:
|
||||||
opts.template_name = "new-machine"
|
opts.template_name = "new-machine"
|
||||||
|
|||||||
Reference in New Issue
Block a user