]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ukify: factor out method for value parsing in ConfigItem
authorJörg Behrmann <behrmann@physik.fu-berlin.de>
Wed, 25 Feb 2026 09:26:15 +0000 (10:26 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 18 May 2026 00:41:22 +0000 (09:41 +0900)
src/ukify/ukify.py

index 4a13019e249f1be33dae3bef1f37e3d668b65692..0377c57ea71cf4938dda3e34c1e44b884be082e5 100755 (executable)
@@ -1859,6 +1859,17 @@ class ConfigItem:
         args = self._names()
         parser.add_argument(*args, **kwargs)
 
+    def parse_value(self, s: str) -> Any:
+        if self.action == argparse.BooleanOptionalAction:
+            # We need to handle this case separately: the options are called
+            # --foo and --no-foo, and no argument is parsed. But in the config
+            # file, we have Foo=yes or Foo=no.
+            return self.parse_boolean(s)
+        elif self.type:
+            return self.type(s)
+
+        return s
+
     def apply_config(
         self,
         namespace: argparse.Namespace,
@@ -1870,24 +1881,13 @@ class ConfigItem:
         assert f'{section}/{key}' == self.config_key
         dest = self.argparse_dest()
 
-        conv: Callable[[str], Any]
-        if self.action == argparse.BooleanOptionalAction:
-            # We need to handle this case separately: the options are called
-            # --foo and --no-foo, and no argument is parsed. But in the config
-            # file, we have Foo=yes or Foo=no.
-            conv = self.parse_boolean
-        elif self.type:
-            conv = self.type
-        else:
-            conv = lambda s: s
-
         # This is a bit ugly, but --initrd and --devicetree-auto are the only options
         # with multiple args on the command line and a space-separated list in the
         # config file.
         if self.name in ['--initrd', '--devicetree-auto']:
-            value = [conv(v) for v in value.split()]
+            value = [self.parse_value(v) for v in value.split()]
         else:
-            value = conv(value)
+            value = self.parse_value(value)
 
         self.config_push(namespace, group, dest, value)