]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Support ListAction with type=Path
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 8 Aug 2022 13:41:14 +0000 (15:41 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 8 Aug 2022 14:22:38 +0000 (16:22 +0200)
We don't yet properly process multiple values of type Path such
as in --extra-tree. This commit updates ListAction to support such
cases.

mkosi/__init__.py

index d5e5bf145256ad81f7470985238eeeed2f824f4c..3f7909520432902e6ddedba008c5ec826a4bb5ae 100644 (file)
@@ -4725,14 +4725,17 @@ class ListAction(argparse.Action):
         if ary is None:
             ary = []
 
-        if isinstance(values, str):
+        if isinstance(values, (str, Path)):
+            # Save the actual type so we can restore it later after processing the argument
+            t = type(values)
+            values = str(values)
             # Support list syntax for comma separated lists as well
             if self.delimiter == "," and values.startswith("[") and values.endswith("]"):
                 values = values[1:-1]
 
             # Make sure delimiters between quotes are ignored.
             # Inspired by https://stackoverflow.com/a/2787979.
-            values = [x.strip() for x in re.split(f"""{self.delimiter}(?=(?:[^'"]|'[^']*'|"[^"]*")*$)""", values) if x]
+            values = [t(x.strip()) for x in re.split(f"""{self.delimiter}(?=(?:[^'"]|'[^']*'|"[^"]*")*$)""", values) if x]
 
         if isinstance(values, list):
             for x in values: