From 24eeda6e228cf9a079a4eca36673b2f83193bd22 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 5 Mar 2021 13:06:12 +0100 Subject: [PATCH] Pass the list of choices to argparse.Action This way our custom ListAction action can properly generate a list of choices in the help message when the metavar is not defined: Before: $ mkosi --help ... --debug SELECTOR Turn on debugging output After: $ mkosi --help ... --debug {run,build-script,workspace-command} Turn on debugging output --- mkosi/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 0baba05fb..dd7e4ad2d 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -4250,7 +4250,9 @@ class ListAction(argparse.Action): def __init__(self, *args: Any, choices: Optional[Iterable[Any]] = None, **kwargs: Any) -> None: self.list_choices = choices - super().__init__(*args, **kwargs) + # mypy doesn't like the following call due to https://github.com/python/mypy/issues/6799, + # so let's, temporarily, ignore the error + super().__init__(choices=choices, *args, **kwargs) # type: ignore[misc] def __call__( self, # These type-hints are copied from argparse.pyi @@ -4815,7 +4817,6 @@ def create_parser() -> ArgumentParserMkosi: action=CommaDelimitedListAction, default=[], help="Turn on debugging output", - metavar="SELECTOR", choices=("run", "build-script", "workspace-command"), ) try: -- 2.47.2