short: Optional[str]
long: Optional[str]
help: Optional[str]
- nargs: Union[str, int]
choices: list[str]
compgen: CompGen
short=next((s for s in action.option_strings if not s.startswith("--")), None),
long=next((s for s in action.option_strings if s.startswith("--")), None),
help=action.help,
- nargs=action.nargs or 0,
choices=[str(c) for c in action.choices] if action.choices is not None else [],
compgen=CompGen.from_action(action),
)
short=setting.short,
long=setting.long,
help=setting.help,
- nargs=setting.nargs or 1,
choices=[str(c) for c in setting.choices] if setting.choices is not None else [],
compgen=CompGen.default,
)
c.write(to_bash_array("_mkosi_options", options_by_key.keys()))
c.write("\n\n")
- nargs = to_bash_hasharray(
- "_mkosi_nargs", {optname: v.nargs for optname, v in options_by_key.items()}
- )
- c.write(nargs)
- c.write("\n\n")
-
choices = to_bash_hasharray(
"_mkosi_choices",
{optname: " ".join(v.choices) for optname, v in options_by_key.items() if v.choices},
c.write(f"-s {option.short.lstrip('-')} ")
if option.long:
c.write(f"-l {option.long.lstrip('-')} ")
- if isinstance(option.nargs, int) and option.nargs > 0:
- c.write("-r ")
+ c.write("-r ")
if option.choices:
c.write('-a "')
c.write(" ".join(option.choices))
long: str = ""
choices: Optional[list[str]] = None
metavar: Optional[str] = None
- nargs: Optional[str] = None
const: Optional[Any] = None
help: Optional[str] = None
ConfigSetting(
dest="repository_key_check",
metavar="BOOL",
- nargs="?",
section="Distribution",
default=True,
parse=config_parse_boolean,
ConfigSetting(
dest="repository_key_fetch",
metavar="BOOL",
- nargs="?",
section="Distribution",
default_factory_depends=("distribution", "tools_tree", "tools_tree_distribution"),
default_factory=config_default_repository_key_fetch,
ConfigSetting(
dest="compress_output",
metavar="ALG",
- nargs="?",
section="Output",
parse=config_parse_compression,
default_factory=config_default_compression,
),
ConfigSetting(
dest="split_artifacts",
- nargs="?",
section="Output",
parse=config_parse_artifact_output_list,
default=ArtifactOutput.compat_no(),
ConfigSetting(
dest="overlay",
metavar="BOOL",
- nargs="?",
section="Output",
parse=config_parse_boolean,
help="Only output the additions on top of the given base trees",
ConfigSetting(
dest="with_recommends",
metavar="BOOL",
- nargs="?",
section="Content",
parse=config_parse_boolean,
help="Install recommended packages",
ConfigSetting(
dest="with_docs",
metavar="BOOL",
- nargs="?",
section="Content",
parse=config_parse_boolean,
default=True,
ConfigSetting(
dest="bootable",
metavar="FEATURE",
- nargs="?",
section="Content",
parse=config_parse_feature,
match=config_match_feature,
ConfigSetting(
dest="microcode_host",
metavar="BOOL",
- nargs="?",
section="Content",
parse=config_parse_boolean,
default=False,
ConfigSetting(
dest="kernel_modules_initrd",
metavar="BOOL",
- nargs="?",
section="Content",
parse=config_parse_boolean,
default=True,
ConfigSetting(
dest="autologin",
short="-a",
+ const=True,
metavar="BOOL",
- nargs="?",
section="Content",
parse=config_parse_boolean,
help="Enable root autologin",
ConfigSetting(
dest="make_initrd",
metavar="BOOL",
- nargs="?",
section="Content",
parse=config_parse_boolean,
help="Make sure the image can be used as an initramfs",
ConfigSetting(
dest="ssh",
metavar="BOOL",
- nargs="?",
section="Content",
parse=config_parse_boolean,
help="Set up SSH access from the host to the final image via 'mkosi ssh'",
ConfigSetting(
dest="secure_boot",
metavar="BOOL",
- nargs="?",
section="Validation",
parse=config_parse_boolean,
help="Sign the resulting kernel/initrd image for UEFI SecureBoot",
ConfigSetting(
dest="checksum",
metavar="BOOL",
- nargs="?",
section="Validation",
parse=config_parse_boolean,
help="Write SHA256SUMS file",
ConfigSetting(
dest="sign",
metavar="BOOL",
- nargs="?",
section="Validation",
parse=config_parse_boolean,
help="Write and sign SHA256SUMS file",
parse=config_make_path_parser(constants=("default",)),
paths=("mkosi.tools",),
help="Look up programs to execute inside the given tree",
- nargs="?",
- const="default",
scope=SettingScope.universal,
),
ConfigSetting(
ConfigSetting(
dest="incremental",
short="-i",
- nargs="?",
+ const=Incremental.yes,
section="Build",
parse=config_make_enum_parser_with_boolean(Incremental, yes=Incremental.yes, no=Incremental.no),
default=Incremental.no,
ConfigSetting(
dest="use_subvolumes",
metavar="FEATURE",
- nargs="?",
section="Build",
parse=config_parse_feature,
help="Use btrfs subvolumes for faster directory operations where possible",
),
ConfigSetting(
dest="build_sources_ephemeral",
- nargs="?",
section="Build",
parse=config_make_enum_parser_with_boolean(
BuildSourcesEphemeral, yes=BuildSourcesEphemeral.yes, no=BuildSourcesEphemeral.no
ConfigSetting(
dest="with_tests",
short="-T",
- long="--without-tests",
- nargs="?",
- const="no",
+ const=False,
section="Build",
parse=config_parse_boolean,
default=True,
ConfigSetting(
dest="with_network",
metavar="BOOL",
- nargs="?",
section="Build",
parse=config_parse_boolean,
help="Run build and postinst scripts with network access (instead of private network)",
"If specified, the container/VM is run with a temporary snapshot of the output "
"image that is removed immediately when the container/VM terminates"
),
- nargs="?",
),
ConfigSetting(
dest="credentials",
ConfigSetting(
dest="console",
metavar="MODE",
- nargs="?",
section="Runtime",
parse=config_make_enum_parser(ConsoleMode),
help="Configure the virtual machine console mode to use",
dest="kvm",
name="KVM",
metavar="FEATURE",
- nargs="?",
section="Runtime",
parse=config_parse_feature,
help="Configure whether to use KVM or not",
dest="vsock",
name="VSock",
metavar="FEATURE",
- nargs="?",
section="Runtime",
parse=config_parse_feature,
help="Configure whether to use vsock or not",
dest="tpm",
name="TPM",
metavar="FEATURE",
- nargs="?",
section="Runtime",
parse=config_parse_feature,
help="Configure whether to use a virtual tpm or not",
dest="cdrom",
name="CDROM",
metavar="BOOLEAN",
- nargs="?",
section="Runtime",
parse=config_parse_boolean,
help="Attach the image as a CD-ROM to the virtual machine",
ConfigSetting(
dest="removable",
metavar="BOOLEAN",
- nargs="?",
section="Runtime",
parse=config_parse_boolean,
help="Attach the image as a removable drive to the virtual machine",
parser.add_argument(
"verb",
type=Verb,
+ nargs="?",
choices=list(Verb),
default=Verb.build,
help=argparse.SUPPRESS,
group = parser.add_argument_group(f"{s.section} configuration options")
last_section = s.section
+ if s.short and s.const is not None:
+ group.add_argument( # type: ignore
+ s.short,
+ metavar="",
+ dest=s.dest,
+ const=s.const,
+ help="",
+ action="store_const",
+ default=argparse.SUPPRESS,
+ )
+
for long in [s.long, *s.compat_longs]:
- opts = [s.short, long] if s.short and long == s.long else [long]
+ opts = [s.short, long] if s.short and long == s.long and s.const is None else [long]
group.add_argument( # type: ignore
*opts,
dest=s.dest,
choices=s.choices,
metavar=s.metavar,
- nargs=s.nargs, # type: ignore
- const=s.const,
help=s.help if long == s.long else argparse.SUPPRESS,
action=ConfigAction,
)
) -> None:
assert option_string is not None
- if values is None and self.nargs == "?":
- values = self.const or "yes"
-
s = SETTINGS_LOOKUP_BY_DEST[self.dest]
if values is None or isinstance(values, str):
) -> tuple[Args, tuple[Config, ...]]:
argv = list(argv)
- # Make sure the verb command gets explicitly passed. Insert a -- before the positional verb argument
- # otherwise it might be considered as an argument of a parameter with nargs='?'. For example mkosi -i
- # summary would be treated as -i=summary.
- for verb in Verb:
- try:
- v_i = argv.index(verb.value)
- except ValueError:
- continue
-
- # Hack to make sure mkosi -C build works.
- if argv[v_i - 1] in ("-C", "--directory"):
- continue
-
- if v_i > 0 and argv[v_i - 1] != "--":
- argv.insert(v_i, "--")
- break
- else:
- argv += ["--", "build"]
-
context = ParseContext(resources)
# The "image" field does not directly map to a setting but is required to determine some default values