clan: remove config subcommand
This removes the `config` subcommand from the cli and the documentation to keep the api surface small. While this functionality was convenient it doesn't need to be surfaced by the clan cli. The remaining `config` python module should be ported to the `clan-app` in a follow up pr. Because the functionality is currently only used by the `clan-app`. Ideally together with: #1830.
This commit is contained in:
@@ -82,7 +82,6 @@ nav:
|
|||||||
- CLI:
|
- CLI:
|
||||||
- reference/cli/index.md
|
- reference/cli/index.md
|
||||||
- reference/cli/backups.md
|
- reference/cli/backups.md
|
||||||
- reference/cli/config.md
|
|
||||||
- reference/cli/facts.md
|
- reference/cli/facts.md
|
||||||
- reference/cli/flakes.md
|
- reference/cli/flakes.md
|
||||||
- reference/cli/flash.md
|
- reference/cli/flash.md
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ __all__ = ["directory", "mdns_discovery", "modules", "update"]
|
|||||||
from . import (
|
from . import (
|
||||||
backups,
|
backups,
|
||||||
clan,
|
clan,
|
||||||
config,
|
|
||||||
facts,
|
facts,
|
||||||
flash,
|
flash,
|
||||||
history,
|
history,
|
||||||
@@ -177,18 +176,6 @@ For more detailed information, visit: {help_hyperlink("getting-started", "https:
|
|||||||
|
|
||||||
clan.register_parser(parser_flake)
|
clan.register_parser(parser_flake)
|
||||||
|
|
||||||
parser_config = subparsers.add_parser(
|
|
||||||
"config",
|
|
||||||
help="read a nixos configuration option",
|
|
||||||
description="read a nixos configuration option",
|
|
||||||
epilog=(
|
|
||||||
"""
|
|
||||||
"""
|
|
||||||
),
|
|
||||||
formatter_class=argparse.RawTextHelpFormatter,
|
|
||||||
)
|
|
||||||
config.register_parser(parser_config)
|
|
||||||
|
|
||||||
parser_ssh = subparsers.add_parser(
|
parser_ssh = subparsers.add_parser(
|
||||||
"ssh",
|
"ssh",
|
||||||
help="ssh to a remote machine",
|
help="ssh to a remote machine",
|
||||||
|
|||||||
@@ -4,12 +4,10 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, get_origin
|
from typing import Any, get_origin
|
||||||
|
|
||||||
from clan_cli.cmd import run
|
from clan_cli.cmd import run
|
||||||
from clan_cli.completions import add_dynamic_completer, complete_machines
|
|
||||||
from clan_cli.dirs import machine_settings_file
|
from clan_cli.dirs import machine_settings_file
|
||||||
from clan_cli.errors import ClanError
|
from clan_cli.errors import ClanError
|
||||||
from clan_cli.git import commit_file
|
from clan_cli.git import commit_file
|
||||||
@@ -305,65 +303,3 @@ def set_option(
|
|||||||
repo_dir=flake_dir,
|
repo_dir=flake_dir,
|
||||||
commit_message=f"Set option {option_description}",
|
commit_message=f"Set option {option_description}",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# takes a (sub)parser and configures it
|
|
||||||
def register_parser(
|
|
||||||
parser: argparse.ArgumentParser | None,
|
|
||||||
) -> None:
|
|
||||||
if parser is None:
|
|
||||||
parser = argparse.ArgumentParser(
|
|
||||||
description="Set or show NixOS options",
|
|
||||||
)
|
|
||||||
|
|
||||||
# inject callback function to process the input later
|
|
||||||
parser.set_defaults(func=get_option)
|
|
||||||
set_machine_action = parser.add_argument(
|
|
||||||
"--machine",
|
|
||||||
"-m",
|
|
||||||
help="Machine to configure",
|
|
||||||
type=str,
|
|
||||||
default="default",
|
|
||||||
)
|
|
||||||
add_dynamic_completer(set_machine_action, complete_machines)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
"--show-trace",
|
|
||||||
help="Show nix trace on evaluation error",
|
|
||||||
action="store_true",
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
"--options-file",
|
|
||||||
help="JSON file with options",
|
|
||||||
type=Path,
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
"--settings-file",
|
|
||||||
help="JSON file with settings",
|
|
||||||
type=Path,
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"--quiet",
|
|
||||||
help="Do not print the value",
|
|
||||||
action="store_true",
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
"option",
|
|
||||||
help="Option to read or set (e.g. foo.bar)",
|
|
||||||
type=str,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def main(argv: list[str] | None = None) -> None:
|
|
||||||
if argv is None:
|
|
||||||
argv = sys.argv
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
register_parser(parser)
|
|
||||||
parser.parse_args(argv[1:])
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ from clan_cli.errors import ClanError, ClanHttpError
|
|||||||
from clan_cli.nix import nix_eval
|
from clan_cli.nix import nix_eval
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: When moving the api to `clan-app`, the whole config module should be
|
||||||
|
# ported to the `clan-app`, because it is not used by the cli at all.
|
||||||
@API.register
|
@API.register
|
||||||
def machine_schema(
|
def machine_schema(
|
||||||
flake_dir: Path,
|
flake_dir: Path,
|
||||||
|
|||||||
@@ -60,9 +60,7 @@ let
|
|||||||
source = runCommand "clan-cli-source" { } ''
|
source = runCommand "clan-cli-source" { } ''
|
||||||
cp -r ${./.} $out
|
cp -r ${./.} $out
|
||||||
chmod -R +w $out
|
chmod -R +w $out
|
||||||
rm $out/clan_cli/config/jsonschema
|
|
||||||
ln -sf ${nixpkgs'} $out/clan_cli/nixpkgs
|
ln -sf ${nixpkgs'} $out/clan_cli/nixpkgs
|
||||||
cp -r ${../../lib/jsonschema} $out/clan_cli/config/jsonschema
|
|
||||||
|
|
||||||
${classgen}/bin/classgen ${inventory-schema}/schema.json $out/clan_cli/inventory/classes.py
|
${classgen}/bin/classgen ${inventory-schema}/schema.json $out/clan_cli/inventory/classes.py
|
||||||
'';
|
'';
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from fixtures_flakes import FlakeForTest
|
|
||||||
from helpers import cli
|
|
||||||
|
|
||||||
from clan_cli import config
|
from clan_cli import config
|
||||||
from clan_cli.config import parsing
|
from clan_cli.config import parsing
|
||||||
@@ -11,28 +9,6 @@ from clan_cli.errors import ClanError
|
|||||||
example_options = f"{Path(config.__file__).parent}/jsonschema/options.json"
|
example_options = f"{Path(config.__file__).parent}/jsonschema/options.json"
|
||||||
|
|
||||||
|
|
||||||
def test_configure_machine(
|
|
||||||
test_flake: FlakeForTest,
|
|
||||||
capsys: pytest.CaptureFixture,
|
|
||||||
) -> None:
|
|
||||||
# clear the output buffer
|
|
||||||
capsys.readouterr()
|
|
||||||
# read a option value
|
|
||||||
cli.run(
|
|
||||||
[
|
|
||||||
"config",
|
|
||||||
"--flake",
|
|
||||||
str(test_flake.path),
|
|
||||||
"-m",
|
|
||||||
"machine1",
|
|
||||||
"clan.jitsi.enable",
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
# read the output
|
|
||||||
assert capsys.readouterr().out == "false\n"
|
|
||||||
|
|
||||||
|
|
||||||
def test_walk_jsonschema_all_types() -> None:
|
def test_walk_jsonschema_all_types() -> None:
|
||||||
schema = dict(
|
schema = dict(
|
||||||
type="object",
|
type="object",
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
import pytest
|
|
||||||
from fixtures_flakes import FlakeForTest
|
|
||||||
|
|
||||||
from clan_cli.clan_uri import FlakeId
|
|
||||||
from clan_cli.config.machine import (
|
|
||||||
config_for_machine,
|
|
||||||
set_config_for_machine,
|
|
||||||
verify_machine_config,
|
|
||||||
)
|
|
||||||
from clan_cli.config.schema import machine_schema
|
|
||||||
from clan_cli.inventory import Machine, MachineDeploy
|
|
||||||
from clan_cli.machines.create import create_machine
|
|
||||||
from clan_cli.machines.list import list_machines
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.with_core
|
|
||||||
def test_schema_for_machine(test_flake_with_core: FlakeForTest) -> None:
|
|
||||||
schema = machine_schema(test_flake_with_core.path, config={})
|
|
||||||
assert "properties" in schema
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.with_core
|
|
||||||
def test_create_machine_on_minimal_clan(test_flake_minimal: FlakeForTest) -> None:
|
|
||||||
assert list_machines(test_flake_minimal.path) == {}
|
|
||||||
|
|
||||||
create_machine(
|
|
||||||
FlakeId(test_flake_minimal.path),
|
|
||||||
Machine(
|
|
||||||
name="foo",
|
|
||||||
system="x86_64-linux",
|
|
||||||
description="A test machine",
|
|
||||||
tags=["test"],
|
|
||||||
icon=None,
|
|
||||||
deploy=MachineDeploy(),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
result = list_machines(test_flake_minimal.path)
|
|
||||||
assert list(result.keys()) == ["foo"]
|
|
||||||
|
|
||||||
# Writes into settings.json
|
|
||||||
set_config_for_machine(
|
|
||||||
test_flake_minimal.path, "foo", dict(services=dict(openssh=dict(enable=True)))
|
|
||||||
)
|
|
||||||
|
|
||||||
config = config_for_machine(test_flake_minimal.path, "foo")
|
|
||||||
assert config["services"]["openssh"]["enable"]
|
|
||||||
assert verify_machine_config(test_flake_minimal.path, "foo") is None
|
|
||||||
Reference in New Issue
Block a user