Pnyx class to access the Fluent API. It uses state-base logic for wiring together
sources, filters, transforms, buffering, and destinations. You can learn more about the internal
State Machine, but can be ignored for simple projects. At a high
level, the state-machine permits method calls in the following sequence:
parseCsv to convert to Row or print to convert to Line. For input and output,
Pnyx expects only 1 call. However, it supports multiple inputs via the cat method, and multiple
outputs via the tee method.
Most of the methods on Pnyx return the Pnyx object, which makes method chaining simple.
await using Pnyx p = new Pnyx();
p.readString("a,b,c,d")
.parseCsv()
.print("$4|$3|$2|$1")
.writeStdout();
// outputs: d|c|b|a
Pnyx has a setting for defaulting input and output to read from StandardIn and StandardOut.
Use this setting when building a command line application with Pnyx for sensible defaults. The following two examples
are equivalent. As you can see, when stdIoDefault is true, Pnyx automatically reads from StandardIn
and writes to StandardOut.
// echos STDIN to STDOUT await using Pnyx p = new Pnyx(); p.readStdin(); p.writeStdout();
// echos STDIN to STDOUT await using Pnyx p = new Pnyx(); p.setSettings(stdIoDefault: true);
Another useful feature of Pnyx is the ability to read command line arguments. This is done by calling the
setCommandLineArgs, readArgs, writeArg methods. When command line arguments
are provided, stdIoDefault setting is ignored in favor of defaulting input/output to the command line arguments.
Pnyx has methods for explicitly read/writing for command line argument. By default, however, Pnyx reads from the
first argument and writes to the second argument, which alleviates explicitly calling readArgs and writeArg
for most usages. The following two examples are equivalent.
// echoes input file (arg #1) to output file (arg #2) await using Pnyx p = new Pnyx(); p.setCommandLineArgs(args); p.readArg(1); p.writeArg(2);
// echoes input file (arg #1) to output file (arg #2) await using Pnyx p = new Pnyx(); p.setCommandLineArgs(args);