Crates.io | picnic-rs |
lib.rs | picnic-rs |
version | 0.1.0 |
source | src |
created_at | 2023-07-12 15:44:06.737851 |
updated_at | 2023-07-12 15:44:06.737851 |
description | PICNIC Is Config Notation Interpreter/Converter |
homepage | |
repository | https://github.com/demfabris/picnic.git |
max_upload_size | |
id | 914588 |
size | 62,515 |
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.
✅ 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)
cargo install picnic-rs
(I'm trying to get ownership for picnic
)
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)
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.
$ 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;
$ 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
curl -o some.json http://config.com/some_json_i_know_not_to_be_malicious.json
eval $(cat some.json | picnic)
Contributions are welcome! Feel free to open an issue or submit a PR.
APACHE-2.0 and MIT
Do not eval output or generate binaries from unknown files!