make config command read-only
This commit is contained in:
@@ -156,8 +156,8 @@ For more detailed information, visit: https://docs.clan.lol/getting-started
|
||||
|
||||
parser_config = subparsers.add_parser(
|
||||
"config",
|
||||
help="set nixos configuration",
|
||||
description="set nixos configuration",
|
||||
help="read a nixos configuration option",
|
||||
description="read a nixos configuration option",
|
||||
epilog=(
|
||||
"""
|
||||
"""
|
||||
|
||||
@@ -150,6 +150,15 @@ def read_machine_option_value(
|
||||
return out
|
||||
|
||||
|
||||
def get_option(args: argparse.Namespace) -> None:
|
||||
print(
|
||||
read_machine_option_value(
|
||||
args.flake, args.machine, args.option, args.show_trace
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# Currently writing is disabled
|
||||
def get_or_set_option(args: argparse.Namespace) -> None:
|
||||
if args.value == []:
|
||||
print(
|
||||
@@ -307,7 +316,7 @@ def register_parser(
|
||||
)
|
||||
|
||||
# inject callback function to process the input later
|
||||
parser.set_defaults(func=get_or_set_option)
|
||||
parser.set_defaults(func=get_option)
|
||||
parser.add_argument(
|
||||
"--machine",
|
||||
"-m",
|
||||
@@ -345,13 +354,6 @@ def register_parser(
|
||||
type=str,
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"value",
|
||||
# force this arg to be set
|
||||
nargs="*",
|
||||
help="option value to set (if omitted, the current value is printed)",
|
||||
)
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> None:
|
||||
if argv is None:
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import json
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from cli import Cli
|
||||
@@ -14,46 +11,6 @@ from clan_cli.errors import ClanError
|
||||
example_options = f"{Path(config.__file__).parent}/jsonschema/options.json"
|
||||
|
||||
|
||||
# use pytest.parametrize
|
||||
@pytest.mark.parametrize(
|
||||
"args,expected",
|
||||
[
|
||||
(["name", "DavHau"], {"name": "DavHau"}),
|
||||
(
|
||||
["kernelModules", "foo", "bar", "baz"],
|
||||
{"kernelModules": ["foo", "bar", "baz"]},
|
||||
),
|
||||
(["services.opt", "test"], {"services": {"opt": "test"}}),
|
||||
(["userIds.DavHau", "42"], {"userIds": {"DavHau": 42}}),
|
||||
],
|
||||
)
|
||||
def test_set_some_option(
|
||||
args: list[str],
|
||||
expected: dict[str, Any],
|
||||
test_flake: FlakeForTest,
|
||||
) -> None:
|
||||
# create temporary file for out_file
|
||||
with tempfile.NamedTemporaryFile() as out_file:
|
||||
with open(out_file.name, "w") as f:
|
||||
json.dump({}, f)
|
||||
cli = Cli()
|
||||
cli.run(
|
||||
[
|
||||
"config",
|
||||
"--flake",
|
||||
str(test_flake.path),
|
||||
"--quiet",
|
||||
"--options-file",
|
||||
example_options,
|
||||
"--settings-file",
|
||||
out_file.name,
|
||||
*args,
|
||||
]
|
||||
)
|
||||
json_out = json.loads(open(out_file.name).read())
|
||||
assert json_out == expected
|
||||
|
||||
|
||||
def test_configure_machine(
|
||||
test_flake: FlakeForTest,
|
||||
temporary_home: Path,
|
||||
@@ -62,17 +19,6 @@ def test_configure_machine(
|
||||
) -> None:
|
||||
cli = Cli()
|
||||
|
||||
cli.run(
|
||||
[
|
||||
"config",
|
||||
"--flake",
|
||||
str(test_flake.path),
|
||||
"-m",
|
||||
"machine1",
|
||||
"clan.jitsi.enable",
|
||||
"true",
|
||||
]
|
||||
)
|
||||
# clear the output buffer
|
||||
capsys.readouterr()
|
||||
# read a option value
|
||||
@@ -88,7 +34,7 @@ def test_configure_machine(
|
||||
)
|
||||
|
||||
# read the output
|
||||
assert capsys.readouterr().out == "true\n"
|
||||
assert capsys.readouterr().out == "false\n"
|
||||
|
||||
|
||||
def test_walk_jsonschema_all_types() -> None:
|
||||
|
||||
@@ -47,16 +47,3 @@ def test_create_flake(
|
||||
flake_outputs["nixosConfigurations"]["machine1"]
|
||||
except KeyError:
|
||||
pytest.fail("nixosConfigurations.machine1 not found in flake outputs")
|
||||
# configure machine1
|
||||
capsys.readouterr()
|
||||
cli.run(["config", "--machine", "machine1", "services.openssh.enable", ""])
|
||||
capsys.readouterr()
|
||||
cli.run(
|
||||
[
|
||||
"config",
|
||||
"--machine",
|
||||
"machine1",
|
||||
"services.openssh.enable",
|
||||
"true",
|
||||
]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user