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:
@@ -4,6 +4,7 @@ import logging
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from clan_lib.clan.create import CreateOptions, create_clan
|
from clan_lib.clan.create import CreateOptions, create_clan
|
||||||
|
from clan_lib.errors import ClanError
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -26,10 +27,10 @@ def register_create_parser(parser: argparse.ArgumentParser) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"path",
|
"name",
|
||||||
type=Path,
|
type=str,
|
||||||
help="Path where to write the clan template to",
|
nargs="?",
|
||||||
default=Path(),
|
help="Name of the clan to create. If not provided, will prompt for a name.",
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -40,9 +41,18 @@ def register_create_parser(parser: argparse.ArgumentParser) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def create_flake_command(args: argparse.Namespace) -> 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(
|
create_clan(
|
||||||
CreateOptions(
|
CreateOptions(
|
||||||
dest=args.path,
|
dest=Path(args.name),
|
||||||
template=args.template,
|
template=args.template,
|
||||||
setup_git=not args.no_git,
|
setup_git=not args.no_git,
|
||||||
src_flake=args.flake,
|
src_flake=args.flake,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import shutil
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from clan_lib.flake import Flake
|
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.
|
Uses `cp -r` to recursively copy the directory.
|
||||||
Ensures the destination directory is writable by the user.
|
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(
|
run(
|
||||||
["chmod", "-R", "u+w", str(dest)]
|
["chmod", "-R", "u+w", str(dest)]
|
||||||
) # Ensure the destination is writable by the user
|
) # Ensure the destination is writable by the user
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
# Ensure this is unique among all clans you want to use.
|
# Ensure this is unique among all clans you want to use.
|
||||||
meta.name = "__CHANGE_ME__";
|
meta.name = "__CHANGE_ME__";
|
||||||
|
|
||||||
|
inventory.machines = {
|
||||||
|
# Define machines here.
|
||||||
|
# jon = { };
|
||||||
|
};
|
||||||
|
|
||||||
# Docs: See https://docs.clan.lol/reference/clanServices
|
# Docs: See https://docs.clan.lol/reference/clanServices
|
||||||
inventory.instances = {
|
inventory.instances = {
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
# Ensure this is unique among all clans you want to use.
|
# Ensure this is unique among all clans you want to use.
|
||||||
meta.name = "__CHANGE_ME__";
|
meta.name = "__CHANGE_ME__";
|
||||||
|
|
||||||
|
inventory.machines = {
|
||||||
|
# Define machines here.
|
||||||
|
# jon = { };
|
||||||
|
};
|
||||||
|
|
||||||
# Docs: See https://docs.clan.lol/reference/clanServices
|
# Docs: See https://docs.clan.lol/reference/clanServices
|
||||||
inventory.instances = {
|
inventory.instances = {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user