Skip to content

Commit

Permalink
Add Format Selector
Browse files Browse the repository at this point in the history
  • Loading branch information
ajxchapman committed Jan 13, 2025
1 parent e54d619 commit 8db212d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,24 @@ def run_all(self, ctx: Context, items:typing.List[SelectorItem]) -> typing.List[
return [x for i, x in enumerate(items) if i in self.index]


class FormatSelector(Selector):
"""
Format a string with the vars values
"""
default_key = "format"
keys = {
"format" : (str, ""),
"var" : (type_none_or_type(str), None)
}

def run(self, ctx: Context, item:SelectorItem) -> typing.List[SelectorItem]:
ctx.push_variable("vars", item.vars)
value = ctx.expand_context(self.format).encode()
ctx.pop_variable("vars")
if self.var is not None:
return [item.clone(vars={self.var: value})]
return [item.clone(value)]

class CacheSelector(Selector):
default_key = "cache_key"
keys = {
Expand Down

0 comments on commit 8db212d

Please sign in to comment.