Merge pull request 'cli/create: add interactive name method' (#4310) from getting-started into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4310
This commit is contained in:
hsjobeki
2025-07-12 13:27:38 +00:00
4 changed files with 27 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ import logging
from pathlib import Path
from clan_lib.clan.create import CreateOptions, create_clan
from clan_lib.errors import ClanError
log = logging.getLogger(__name__)
@@ -26,10 +27,10 @@ def register_create_parser(parser: argparse.ArgumentParser) -> None:
)
parser.add_argument(
"path",
type=Path,
help="Path where to write the clan template to",
default=Path(),
"name",
type=str,
nargs="?",
help="Name of the clan to create. If not provided, will prompt for a name.",
)
parser.add_argument(
@@ -40,9 +41,18 @@ def register_create_parser(parser: argparse.ArgumentParser) -> None:
)
def create_flake_command(args: argparse.Namespace) -> None:
# Ask for a path interactively if none provided
if args.name is None:
user_input = input("Enter a name for the new clan: ").strip()
if not user_input:
msg = "Error: name is required."
raise ClanError(msg)
args.name = Path(user_input)
create_clan(
CreateOptions(
dest=args.path,
dest=Path(args.name),
template=args.template,
setup_git=not args.no_git,
src_flake=args.flake,

View File

@@ -1,3 +1,4 @@
import shutil
from pathlib import Path
from clan_lib.flake import Flake
@@ -35,7 +36,7 @@ def copy_from_nixstore(src: Path, dest: Path) -> None:
Uses `cp -r` to recursively copy the directory.
Ensures the destination directory is writable by the user.
"""
run(["cp", "-r", str(src / "."), str(dest)]) # Copy contents of src to dest
shutil.copytree(src, dest, dirs_exist_ok=True, symlinks=True)
run(
["chmod", "-R", "u+w", str(dest)]
) # Ensure the destination is writable by the user

View File

@@ -2,6 +2,11 @@
# Ensure this is unique among all clans you want to use.
meta.name = "__CHANGE_ME__";
inventory.machines = {
# Define machines here.
# jon = { };
};
# Docs: See https://docs.clan.lol/reference/clanServices
inventory.instances = {

View File

@@ -2,6 +2,11 @@
# Ensure this is unique among all clans you want to use.
meta.name = "__CHANGE_ME__";
inventory.machines = {
# Define machines here.
# jon = { };
};
# Docs: See https://docs.clan.lol/reference/clanServices
inventory.instances = {