jkcfg / jk

Configuration as Code with ECMAScript
https://jkcfg.github.io
Apache License 2.0
404 stars 30 forks source link

More control over in/out formats #357

Open squaremo opened 4 years ago

squaremo commented 4 years ago

This adds a flag jk generate --format, which will force the output to either YAML or JSON.

If printing to stdout, this means all values are printed as whichever foramt, with streams being inlined as before.

If writing to files, the file extension when present will be changed. Values with a stream (or multidoc) format -- YAMLStream, JSONStream -- will still be written as streams.

Using an argument of - now instructs jk transform to read values from stdin (as well as any files supplied as arguments).

The new flag --stdin-format tells it what format to expect (it defaults to 'yaml'). The possible values are json meaning expect JSON values, and yaml meaning expect a YAML stream.

some-process | jk transform --stdin-format=json  -m transform/module -

Reading from stdin implies --stdout as well, since the alternative is to make up a filename to write it to. I'm not sure of the ergonomics of that choice.