Skip to content

Commit

Permalink
Add glob matching in tags
Browse files Browse the repository at this point in the history
  • Loading branch information
neoxelox committed Aug 24, 2022
1 parent d9f4fe0 commit 1efae8a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions superinvoke/objects/common.py
Original file line number Diff line number Diff line change
@@ -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(<glob>) 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)]

0 comments on commit 1efae8a

Please sign in to comment.