cli: rename admin create to create

This commit is contained in:
Jörg Thalheim 2023-09-15 16:36:09 +02:00
parent 164f95723d
commit f6a7e42e38
4 changed files with 16 additions and 34 deletions

View File

@ -4,7 +4,7 @@ import sys
from types import ModuleType
from typing import Optional
from . import admin, config, machines, secrets, webui, zerotier
from . import config, create, machines, secrets, webui, zerotier
from .errors import ClanError
from .ssh import cli as ssh_cli
@ -19,8 +19,8 @@ def create_parser(prog: Optional[str] = None) -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(prog=prog, description="cLAN tool")
subparsers = parser.add_subparsers()
parser_admin = subparsers.add_parser("admin", help="administrate a clan")
admin.register_parser(parser_admin)
parser_create = subparsers.add_parser("create", help="create a clan flake")
create.register_parser(parser_create)
# DISABLED: this currently crashes if a flake does not define .#clanOptions
if os.environ.get("CLAN_OPTIONS_FILE") is not None:

View File

@ -1,13 +1,11 @@
# !/usr/bin/env python3
import argparse
import os
import subprocess
from .nix import nix_command
def create(args: argparse.Namespace) -> None:
os.makedirs(args.folder, exist_ok=True)
# TODO create clan template in flake
subprocess.run(
nix_command(
@ -24,18 +22,4 @@ def create(args: argparse.Namespace) -> None:
# takes a (sub)parser and configures it
def register_parser(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"-f",
"--folder",
help="the folder where the clan is defined, default to the current folder",
default=os.getcwd(),
)
subparser = parser.add_subparsers(
title="command",
description="the command to run",
help="the command to run",
required=True,
)
parser_create = subparser.add_parser("create", help="create a new clan")
parser_create.set_defaults(func=create)
parser.set_defaults(func=create)

View File

@ -1,14 +0,0 @@
from typing import Union
import pytest_subprocess.fake_process
from cli import Cli
from pytest_subprocess import utils
# using fp fixture from pytest-subprocess
def test_create(fp: pytest_subprocess.fake_process.FakeProcess) -> None:
cmd: list[Union[str, utils.Any]] = ["nix", "flake", "init", "-t", fp.any()]
fp.register(cmd)
cli = Cli()
cli.run(["admin", "--folder", "./my-clan", "create"])
assert fp.call_count(cmd) == 1

View File

@ -0,0 +1,12 @@
from pathlib import Path
import pytest
from cli import Cli
@pytest.mark.impure
def test_template(monkeypatch: pytest.MonkeyPatch, temporary_dir: Path) -> None:
monkeypatch.chdir(temporary_dir)
cli = Cli()
cli.run(["create"])
assert (temporary_dir / ".clan-flake").exists()