From 1efae8ad987b531f056114be6fb09ab78500459c Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 25 Aug 2022 01:40:23 +0200 Subject: [PATCH] Add glob matching in tags --- superinvoke/objects/common.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/superinvoke/objects/common.py b/superinvoke/objects/common.py index ca4a550..9e7ebe9 100644 --- a/superinvoke/objects/common.py +++ b/superinvoke/objects/common.py @@ -1,8 +1,33 @@ +import fnmatch +from typing import List + from .. import utils # Represents the list of available tags. class Tags(utils.StrEnum): + @utils.classproperty + def All(cls) -> List[str]: + all = [] + + for tag in dir(cls): + if tag in ["All", "ALL"]: + continue + + tag = getattr(cls, tag) + if isinstance(tag, Tags): + all.append(tag) + + return all + @utils.classproperty def ALL(cls): + """ + Deprecated. Use As() with unpacking. + Example: tags=[*Tags.As("*")] + """ return "*" + + @classmethod + def As(cls, tag: str) -> List[str]: + return [tag_ for tag_ in cls.All if fnmatch.filter([tag_], tag)]