Alogani / asyncproc

Flexible child process spawner with strong async features
MIT License
11 stars 1 forks source link

Proposal: Add Piping #13

Open Alogani opened 1 month ago

Alogani commented 1 month ago

It should be a nice feature to have some sort of piping for conciseness, like in bash echo num | sed s/u/i/

Examples

Here is a working example/proof of concept

import asyncproc ## v0.4.2
import macros

macro `|`(a, b: typed): Future[string] =
    var newB = b.copyNimTree()
    let shSym = b[1]
    newB[1] = quote do:
        `shSym`.merge(input = some AsyncioBase(AsyncString.new(await `a`)))
    quote do:
        `newB`  

var sh = sh.merge(prefixCmd = some @["sh", "-c"], toRemove = { QuoteArgs })

proc main() {.async.} =
    echo await (sh.runGetOutput(@["echo", "'54\n'"]) |
        sh.runGetOutput(@["read a; echo a=$a'\n'"]) |
        sh.runGetOutput(@["read b; echo b=$b'\n'"]))

waitFor main()

Problematics

Here are some pain points before including it in the library