Hey community,
In the context of building some CLI utilities for private use, I found Foundation's Process
API a tad too dynamic. That's great if you want Process
to model both "function-like" utilities and interactive applications, but it's not so good if you try to just call grep
or build a small pipeline.
This is where my latest project comes in: process-kit.
Basically, it allows you to describe the utility you'd like to use like this:
struct Grep : Proc {
typealias Input = StringPipe
typealias Output = StringPipe
let pattern : String
func path() throws -> URL {
// lookup via PATH
try .findExecutable(named: "grep")
}
var arguments: [String] {
[pattern]
}
}
And you can write typesafe pipelines like this:
let myProc = Pipeline {
MyUtil1()
MyUtil2(MyArgs(), 42)
MyUtil3("Hello, World!")
//... all as typesafe as your Procs make it!
}
Both Input
and Output
are expected to conform to the Tipe
protocol ("Typed pIPE"), and if they additionally conform to PipeEncodable
and TypeDecodable
(which is true for the provided implementations VoidPipe
, StringPipe
and JSONPipe
), you can initialize them with plain swift types or read the stored value as plain swift type.
Enjoy!