nixos-rebuild-ng: move grouping of nix args to parse_args
This commit is contained in:
@@ -198,13 +198,15 @@ def get_main_parser() -> argparse.ArgumentParser:
|
||||
|
||||
def parse_args(
|
||||
argv: list[str],
|
||||
) -> tuple[argparse.Namespace, dict[str, argparse.Namespace]]:
|
||||
) -> tuple[argparse.Namespace, GroupedNixArgs]:
|
||||
parser, sub_parsers = get_parser()
|
||||
args = parser.parse_args(argv[1:])
|
||||
args_groups = {
|
||||
group: parser.parse_known_args(argv[1:])[0]
|
||||
for group, parser in sub_parsers.items()
|
||||
}
|
||||
grouped_nix_args = GroupedNixArgs.from_parsed_args_groups(
|
||||
{
|
||||
group: parser.parse_known_args(argv[1:])[0]
|
||||
for group, parser in sub_parsers.items()
|
||||
}
|
||||
)
|
||||
|
||||
if args.help or args.action is None:
|
||||
if WITH_SHELL_FILES:
|
||||
@@ -266,12 +268,11 @@ def parse_args(
|
||||
if args.flake and (args.file or args.attr):
|
||||
parser.error("--flake cannot be used with --file or --attr")
|
||||
|
||||
return args, args_groups
|
||||
return args, grouped_nix_args
|
||||
|
||||
|
||||
def execute(argv: list[str]) -> None:
|
||||
args, args_groups = parse_args(argv)
|
||||
grouped_nix_args = GroupedNixArgs.from_parsed_args_groups(args_groups)
|
||||
args, grouped_nix_args = parse_args(argv)
|
||||
|
||||
if args.upgrade or args.upgrade_all:
|
||||
nix.upgrade_channels(args.upgrade_all, args.sudo)
|
||||
|
||||
@@ -65,8 +65,7 @@ def test_parse_args() -> None:
|
||||
assert r1.install_grub is True
|
||||
assert r1.profile_name == "system"
|
||||
assert r1.action == "switch"
|
||||
# round-trip test (ensure that we have the same flags as parsed)
|
||||
assert nr.utils.dict_to_flags(vars(g1["common_flags"])) == [
|
||||
assert nr.utils.dict_to_flags(g1.common_flags) == [
|
||||
"--option",
|
||||
"foo1",
|
||||
"bar1",
|
||||
@@ -74,7 +73,13 @@ def test_parse_args() -> None:
|
||||
"foo2",
|
||||
"bar2",
|
||||
]
|
||||
assert nr.utils.dict_to_flags(vars(g1["flake_common_flags"])) == [
|
||||
assert nr.utils.dict_to_flags(g1.flake_common_flags) == [
|
||||
"--option",
|
||||
"foo1",
|
||||
"bar1",
|
||||
"--option",
|
||||
"foo2",
|
||||
"bar2",
|
||||
"--update-input",
|
||||
"input1",
|
||||
"--update-input",
|
||||
@@ -112,13 +117,15 @@ def test_parse_args() -> None:
|
||||
assert r2.action == "dry-build"
|
||||
assert r2.file == "foo"
|
||||
assert r2.attr == "bar"
|
||||
# round-trip test (ensure that we have the same flags as parsed)
|
||||
assert nr.utils.dict_to_flags(vars(g2["common_flags"])) == [
|
||||
assert nr.utils.dict_to_flags(g2.common_flags) == [
|
||||
"-vvv",
|
||||
"--quiet",
|
||||
"--quiet",
|
||||
]
|
||||
assert nr.utils.dict_to_flags(vars(g2["common_build_flags"])) == [
|
||||
assert nr.utils.dict_to_flags(g2.build_flags) == [
|
||||
"-vvv",
|
||||
"--quiet",
|
||||
"--quiet",
|
||||
"--include",
|
||||
"include1",
|
||||
"--include",
|
||||
|
||||
Reference in New Issue
Block a user