nixos-rebuild-ng: fix --option parse, make --quiet a count
Fix #374050.
This commit is contained in:
@@ -34,12 +34,12 @@ def get_parser() -> tuple[argparse.ArgumentParser, dict[str, argparse.ArgumentPa
|
||||
common_flags.add_argument("--keep-failed", "-K", action="store_true")
|
||||
common_flags.add_argument("--fallback", action="store_true")
|
||||
common_flags.add_argument("--repair", action="store_true")
|
||||
common_flags.add_argument("--option", nargs=2)
|
||||
common_flags.add_argument("--option", nargs=2, action="append")
|
||||
|
||||
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="store_true")
|
||||
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")
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import logging
|
||||
from collections.abc import Mapping, Sequence
|
||||
from typing import Any, assert_never, override
|
||||
|
||||
type Arg = bool | str | list[str] | int | None
|
||||
type Arg = bool | str | list[str] | list[list[str]] | int | None
|
||||
type Args = dict[str, Arg]
|
||||
|
||||
|
||||
@@ -43,9 +43,13 @@ def dict_to_flags(d: Args | None) -> list[str]:
|
||||
flags.append(flag)
|
||||
flags.append(value)
|
||||
case list():
|
||||
for v in value:
|
||||
for vs in value:
|
||||
flags.append(flag)
|
||||
flags.append(v)
|
||||
if isinstance(vs, list):
|
||||
for v in vs:
|
||||
flags.append(v)
|
||||
else:
|
||||
flags.append(vs)
|
||||
case _:
|
||||
assert_never(value)
|
||||
return flags
|
||||
|
||||
@@ -50,8 +50,8 @@ 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"]
|
||||
assert r1.option == [["foo", "bar"]]
|
||||
assert g1["common_flags"].option == [["foo", "bar"]]
|
||||
|
||||
r2, g2 = nr.parse_args(
|
||||
[
|
||||
@@ -292,6 +292,10 @@ def test_execute_nix_switch_flake(mock_run: Any, tmp_path: Path) -> None:
|
||||
"--sudo",
|
||||
"--verbose",
|
||||
"--fast",
|
||||
# https://github.com/NixOS/nixpkgs/issues/374050
|
||||
"--option",
|
||||
"narinfo-cache-negative-ttl",
|
||||
"1200",
|
||||
]
|
||||
)
|
||||
|
||||
@@ -307,6 +311,9 @@ def test_execute_nix_switch_flake(mock_run: Any, tmp_path: Path) -> None:
|
||||
"--print-out-paths",
|
||||
"/path/to/config#nixosConfigurations.hostname.config.system.build.toplevel",
|
||||
"-v",
|
||||
"--option",
|
||||
"narinfo-cache-negative-ttl",
|
||||
"1200",
|
||||
"--no-link",
|
||||
],
|
||||
check=True,
|
||||
|
||||
@@ -11,10 +11,11 @@ def test_dict_to_flags() -> None:
|
||||
"test_flag_2": False,
|
||||
"test_flag_3": "value",
|
||||
"test_flag_4": ["v1", "v2"],
|
||||
"test_flag_5": None,
|
||||
"test_flag_5": [["o1", "v1"], ["o2", "v2"]],
|
||||
"test_flag_6": None,
|
||||
"t": True,
|
||||
"v": 5,
|
||||
"verbose": 2,
|
||||
"quiet": 2,
|
||||
}
|
||||
)
|
||||
assert r1 == [
|
||||
@@ -25,10 +26,16 @@ def test_dict_to_flags() -> None:
|
||||
"v1",
|
||||
"--test-flag-4",
|
||||
"v2",
|
||||
"--test-flag-5",
|
||||
"o1",
|
||||
"v1",
|
||||
"--test-flag-5",
|
||||
"o2",
|
||||
"v2",
|
||||
"-t",
|
||||
"-vvvvv",
|
||||
"--verbose",
|
||||
"--verbose",
|
||||
"--quiet",
|
||||
"--quiet",
|
||||
]
|
||||
r2 = u.dict_to_flags({"verbose": 0, "empty_list": []})
|
||||
assert r2 == []
|
||||
|
||||
Reference in New Issue
Block a user