]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Pass the list of choices to argparse.Action 671/head
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 5 Mar 2021 12:06:12 +0000 (13:06 +0100)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 5 Mar 2021 12:44:15 +0000 (13:44 +0100)
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

index 0baba05fb0453fa22e95a06aa04e18d57b469085..dd7e4ad2d448dd3ba9155f73153bd5c7ff0c083b 100644 (file)
@@ -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: