1 unstable release
0.1.0 | Jul 12, 2023 |
---|
#2991 in Parser implementations
29KB
597 lines
PICNIC Is Config Notation Interpreter/Converter 🦀
PICNIC
PICNIC's name is powered by AI, which immediately makes it worth your time:
Human: Please come up with a recursive name for my cli project which interprets configuration files and prints environment variables.
ChatGPT: That sounds like a useful tool! How about naming it PICNIC, which stands for "PICNIC Is Config Notation Interpreter/Converter". This fits the recursive acronym style you're looking for, and it also gives a sense of ease and simplicity, as if dealing with various config file formats is just a "picnic" with this tool.
Features
✅ Extract data from json
and .env
files (soon yaml
, toml
, csv
, xml
)
✅ Match keys with the same syntax as your file format
✅ Output matched results, or everything. Source it with eval
✅ Optionally spawn tiny binaries that print your values (useful when outside shell scripting, e.g. Nix)
Installation
From crates.io
cargo install picnic-rs
(I'm trying to get ownership for picnic
)
Usage
Some json examples.
The usage is similar for other formats. picnic --help
for more info.
// some.json
{
"foo": "bar",
"baz": {
"quz": "qork"
},
"boo": [
"bah",
{
"lol": "lurg"
}
]
}
$ picnic some.json
Output:
baz.quz=qork; export baz.quz;
boo.0=bah; export boo.0;
boo.1.lol=lurg; export boo.1.lol;
foo=bar; export foo;
Eval the output to set the environment variables:
eval $(picnic some.json)
⭐ Matching templates
Replace the values you want to extract with $
variables:
$ picnic some.json --match '{"boo": [$BAH, "lol": $LURG] }'
Output:
BAH=bah; export BAH;
LURG=lurg; export LURG;
Similarly, eval the output to set the env variables.
📝 Custom separators and casing options
$ picnic some.json --separator _ --casing upper
Output:
BAZ_QUZ=qork; export BAZ_QUZ;
BOO_0=bah; export BOO_0;
BOO_1_LOL=lurg; export BOO_1_LOL;
FOO=bar; export FOO;
💾 Spawn binaries
$ picnic some.json --spawn /tmp
Generates:
$ ls /tmp
foo
baz.quz
boo.0
boo.1.lol
Outputs:
$ ./foo
bar
$ ./baz.quz
qork
$ ./boo.0
bah
$ ./boo.1.lol
lurg
↩︎ Pipe stdin to picnic
curl -o some.json http://config.com/some_json_i_know_not_to_be_malicious.json
eval $(cat some.json | picnic)
Contributing
Contributions are welcome! Feel free to open an issue or submit a PR.
License
APACHE-2.0 and MIT
Disclaimer
Do not eval output or generate binaries from unknown files!
Dependencies
~5.5–7.5MB
~138K SLoC