build-deps.py: add kw args

So now user doesn't have to provide positional args they don't need if they're fine with the defaults - e.g. `python build-deps.py --build-cfg Debug`.
This commit is contained in:
Andrej730
2026-09-11 10:58:48 +05:00
parent 3be454447f
commit fb0a826ac9
+36 -6
View File
@@ -136,7 +136,7 @@ def print_success(start_time: datetime) -> None:
def parse_args() -> Args: def parse_args() -> Args:
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument( parser.add_argument(
"generator", "generator",
nargs="?", nargs="?",
@@ -149,19 +149,41 @@ def parse_args() -> Args:
"(3) full CMake generator name, e.g. 'Visual Studio 17 2022'." "(3) full CMake generator name, e.g. 'Visual Studio 17 2022'."
), ),
) )
parser.add_argument(
"--generator",
dest="generator_flag",
default=None,
help="Alternative way to specify the generator, instead of the positional argument. See above for accepted forms.",
)
# SUPPRESS avoids a misleading "(default: None)" in `--help`,
# though then arg might not be set and we use `getattr` to get it.
parser.add_argument( parser.add_argument(
"build_cfg", "build_cfg",
nargs="?", nargs="?",
default=argparse.SUPPRESS,
choices=BUILD_CFGS,
help=f"Build configuration type. (default: {BUILD_CFG_DEFAULT})",
)
parser.add_argument(
"--build-cfg",
dest="build_cfg_flag",
default=BUILD_CFG_DEFAULT, default=BUILD_CFG_DEFAULT,
choices=BUILD_CFGS, choices=BUILD_CFGS,
help="Build configuration type. Uses default if not provided.", help="Alternative way to specify the build configuration type, instead of the positional argument.",
) )
parser.add_argument( parser.add_argument(
"build_type", "build_type",
nargs="?", nargs="?",
default=argparse.SUPPRESS,
choices=BUILD_TYPES,
help=f"Build type. (default: {BUILD_TYPE_DEFAULT})",
)
parser.add_argument(
"--build-type",
dest="build_type_flag",
default=BUILD_TYPE_DEFAULT, default=BUILD_TYPE_DEFAULT,
choices=BUILD_TYPES, choices=BUILD_TYPES,
help="Build type.", help="Alternative way to specify the build type, instead of the positional argument.",
) )
parser.add_argument( parser.add_argument(
"--log-level", "--log-level",
@@ -180,10 +202,18 @@ def parse_args() -> Args:
) )
args = parser.parse_args() args = parser.parse_args()
logger.setLevel(args.log_level) logger.setLevel(args.log_level)
if args.generator is not None and args.generator_flag is not None:
parser.error("generator was specified both as a positional argument and as --generator.")
generator = args.generator or args.generator_flag
build_cfg = getattr(args, "build_cfg", None) or args.build_cfg_flag
build_type = getattr(args, "build_type", None) or args.build_type_flag
return Args( return Args(
generator=args.generator, generator=generator,
build_cfg=args.build_cfg, build_cfg=build_cfg,
build_type=args.build_type, build_type=build_type,
reuse_boost=args.reuse_boost, reuse_boost=args.reuse_boost,
) )