in antlir/nspawn_in_subvol/args.py [0:0]
def _parse_cli_args(argv, *, allow_debug_only_opts) -> _NspawnOpts:
"Keep in sync with `_NspawnCLIArgs`"
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
"--append-console",
# This is used when the bare option with no arg is used.
const=None,
# This is used when no switch is provided
default=subprocess.DEVNULL,
nargs="?",
# This is used only when an argument is provided
type=Path.from_argparse,
help="Where to send console output. If "
"--append-console=/path/to/file is "
"provided, append the console output to the supplied file. If "
"just --append-console is provided, send to stderr for easier "
"debugging. By default the console output is supressed.",
)
_parser_add_nspawn_opts(parser)
_parser_add_plugin_args(parser)
add_targets_and_outputs_arg(parser)
if allow_debug_only_opts:
_parser_add_debug_only_not_for_prod_opts(parser)
args = Path.parse_args(parser, argv)
if allow_debug_only_opts and args.register:
assert (
args.register and args.boot
), "--register can only be used with --boot"
layer_path = args.layer_path
del args.layer_path
args.layer = find_built_subvol(layer_path)
args.subvolume_on_disk = find_subvolume_on_disk(layer_path)
return _extract_opts_from_dict(
_new_nspawn_cli_args,
_NspawnCLIArgs._fields,
args.__dict__,
opts=_extract_opts_from_dict(
new_nspawn_opts,
_NspawnOpts._fields,
args.__dict__,
debug_only_opts=_extract_opts_from_dict(
_new_nspawn_debug_only_not_for_prod_opts,
_NspawnDebugOnlyNotForProdOpts._fields
if allow_debug_only_opts
else (),
args.__dict__,
),
),
plugin_args=_extract_opts_from_dict(
NspawnPluginArgs, NspawnPluginArgs._fields, args.__dict__
),
)