Skip to content

Commit

Permalink
Update __init__.py
Browse files Browse the repository at this point in the history
  • Loading branch information
anki-code authored Feb 14, 2024
1 parent 9fc6287 commit 559df01
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions xontrib/pipeliner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
from xonsh.tools import print_color
from xontrib_pipeliner_asttokens import asttokens

_default_presets = {
"strip": "line.strip()",
"split": lambda args: f"line.split({repr(args[0])})"
}

def _pl(args, stdin, stdout):
err = False
if len(args) == 0:
Expand All @@ -18,6 +23,11 @@ def _pl(args, stdin, stdout):
print('Example: echo "123" | pl "line[::-1]"', file=sys.stderr)
return

presets = {**_default_presets, **__xonsh__.env.get('XONTRIB_PIPELINER_PRESETS', {})}
if args[0] in presets:
preset = presets[args[0]]
args = [preset(args[1:])] if callable(preset) else [preset]

fn = eval('lambda line, num:'+args[0], __xonsh__.ctx)

if stdin is None:
Expand Down

0 comments on commit 559df01

Please sign in to comment.