From 23ab763be03ff28fbbdae9fda79c24821385f93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 19 Dec 2024 00:44:40 +0100 Subject: [PATCH] gdctl: Add None friendly named enum helper to create from string If the string is None, don't create a named enum instance. Part-of: --- tools/gdctl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/gdctl b/tools/gdctl index bd8df818e..5bd5b3236 100755 --- a/tools/gdctl +++ b/tools/gdctl @@ -28,6 +28,17 @@ class NamedEnum(Enum): if string == enum_string ) + @classmethod + def maybe_from_string(cls, string): + if string: + return next( + enum + for enum, enum_string in cls.enum_names() + if string == enum_string + ) + else: + return None + class Transform(NamedEnum): NORMAL = 0