cli: rename admin create to create
This commit is contained in:
@@ -4,7 +4,7 @@ import sys
|
|||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
from typing import Optional
|
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 .errors import ClanError
|
||||||
from .ssh import cli as ssh_cli
|
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")
|
parser = argparse.ArgumentParser(prog=prog, description="cLAN tool")
|
||||||
subparsers = parser.add_subparsers()
|
subparsers = parser.add_subparsers()
|
||||||
|
|
||||||
parser_admin = subparsers.add_parser("admin", help="administrate a clan")
|
parser_create = subparsers.add_parser("create", help="create a clan flake")
|
||||||
admin.register_parser(parser_admin)
|
create.register_parser(parser_create)
|
||||||
|
|
||||||
# DISABLED: this currently crashes if a flake does not define .#clanOptions
|
# DISABLED: this currently crashes if a flake does not define .#clanOptions
|
||||||
if os.environ.get("CLAN_OPTIONS_FILE") is not None:
|
if os.environ.get("CLAN_OPTIONS_FILE") is not None:
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
# !/usr/bin/env python3
|
# !/usr/bin/env python3
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from .nix import nix_command
|
from .nix import nix_command
|
||||||
|
|
||||||
|
|
||||||
def create(args: argparse.Namespace) -> None:
|
def create(args: argparse.Namespace) -> None:
|
||||||
os.makedirs(args.folder, exist_ok=True)
|
|
||||||
# TODO create clan template in flake
|
# TODO create clan template in flake
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
nix_command(
|
nix_command(
|
||||||
@@ -24,18 +22,4 @@ def create(args: argparse.Namespace) -> None:
|
|||||||
|
|
||||||
# takes a (sub)parser and configures it
|
# takes a (sub)parser and configures it
|
||||||
def register_parser(parser: argparse.ArgumentParser) -> None:
|
def register_parser(parser: argparse.ArgumentParser) -> None:
|
||||||
parser.add_argument(
|
parser.set_defaults(func=create)
|
||||||
"-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)
|
|
||||||
@@ -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
|
|
||||||
12
pkgs/clan-cli/tests/test_clan_template.py
Normal file
12
pkgs/clan-cli/tests/test_clan_template.py
Normal 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()
|
||||||
Reference in New Issue
Block a user