nixos-rebuild-ng: fix --quiet and --override-input
This commit is contained in:
@@ -27,6 +27,7 @@ def get_parser() -> tuple[argparse.ArgumentParser, dict[str, argparse.ArgumentPa
|
||||
default=0,
|
||||
help="Enable verbose logging (includes nix)",
|
||||
)
|
||||
common_flags.add_argument("--quiet", action="count", default=0)
|
||||
common_flags.add_argument("--max-jobs", "-j")
|
||||
common_flags.add_argument("--cores")
|
||||
common_flags.add_argument("--log-format")
|
||||
@@ -39,7 +40,6 @@ def get_parser() -> tuple[argparse.ArgumentParser, dict[str, argparse.ArgumentPa
|
||||
common_build_flags = argparse.ArgumentParser(add_help=False)
|
||||
common_build_flags.add_argument("--builders")
|
||||
common_build_flags.add_argument("--include", "-I", action="append")
|
||||
common_build_flags.add_argument("--quiet", action="count", default=0)
|
||||
common_build_flags.add_argument("--print-build-logs", "-L", action="store_true")
|
||||
common_build_flags.add_argument("--show-trace", action="store_true")
|
||||
|
||||
@@ -55,7 +55,7 @@ def get_parser() -> tuple[argparse.ArgumentParser, dict[str, argparse.ArgumentPa
|
||||
flake_common_flags.add_argument("--no-registries", action="store_true")
|
||||
flake_common_flags.add_argument("--commit-lock-file", action="store_true")
|
||||
flake_common_flags.add_argument("--update-input")
|
||||
flake_common_flags.add_argument("--override-input", nargs=2)
|
||||
flake_common_flags.add_argument("--override-input", nargs=2, action="append")
|
||||
|
||||
classic_build_flags = argparse.ArgumentParser(add_help=False)
|
||||
classic_build_flags.add_argument("--no-build-output", "-Q", action="store_true")
|
||||
|
||||
@@ -40,8 +40,17 @@ def test_parse_args() -> None:
|
||||
"--flake",
|
||||
"/etc/nixos",
|
||||
"--option",
|
||||
"foo",
|
||||
"bar",
|
||||
"foo1",
|
||||
"bar1",
|
||||
"--option",
|
||||
"foo2",
|
||||
"bar2",
|
||||
"--override-input",
|
||||
"override1",
|
||||
"input1",
|
||||
"--override-input",
|
||||
"override2",
|
||||
"input2",
|
||||
]
|
||||
)
|
||||
assert nr.logger.level == logging.INFO
|
||||
@@ -50,8 +59,23 @@ def test_parse_args() -> None:
|
||||
assert r1.install_grub is True
|
||||
assert r1.profile_name == "system"
|
||||
assert r1.action == "switch"
|
||||
assert r1.option == [["foo", "bar"]]
|
||||
assert g1["common_flags"].option == [["foo", "bar"]]
|
||||
# round-trip test (ensure that we have the same flags as parsed)
|
||||
assert nr.utils.dict_to_flags(vars(g1["common_flags"])) == [
|
||||
"--option",
|
||||
"foo1",
|
||||
"bar1",
|
||||
"--option",
|
||||
"foo2",
|
||||
"bar2",
|
||||
]
|
||||
assert nr.utils.dict_to_flags(vars(g1["flake_common_flags"])) == [
|
||||
"--override-input",
|
||||
"override1",
|
||||
"input1",
|
||||
"--override-input",
|
||||
"override2",
|
||||
"input2",
|
||||
]
|
||||
|
||||
r2, g2 = nr.parse_args(
|
||||
[
|
||||
@@ -63,7 +87,13 @@ def test_parse_args() -> None:
|
||||
"foo",
|
||||
"--attr",
|
||||
"bar",
|
||||
"-I",
|
||||
"include1",
|
||||
"-I",
|
||||
"include2",
|
||||
"-vvv",
|
||||
"--quiet",
|
||||
"--quiet",
|
||||
]
|
||||
)
|
||||
assert nr.logger.level == logging.DEBUG
|
||||
@@ -72,7 +102,18 @@ def test_parse_args() -> None:
|
||||
assert r2.action == "dry-build"
|
||||
assert r2.file == "foo"
|
||||
assert r2.attr == "bar"
|
||||
assert g2["common_flags"].v == 3
|
||||
# round-trip test (ensure that we have the same flags as parsed)
|
||||
assert nr.utils.dict_to_flags(vars(g2["common_flags"])) == [
|
||||
"-vvv",
|
||||
"--quiet",
|
||||
"--quiet",
|
||||
]
|
||||
assert nr.utils.dict_to_flags(vars(g2["common_build_flags"])) == [
|
||||
"--include",
|
||||
"include1",
|
||||
"--include",
|
||||
"include2",
|
||||
]
|
||||
|
||||
|
||||
@patch.dict(nr.process.os.environ, {}, clear=True)
|
||||
|
||||
Reference in New Issue
Block a user