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](https://crates.io/crates/picnic-rs)
`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.
```json
// some.json
{
"foo": "bar",
"baz": {
"quz": "qork"
},
"boo": [
"bah",
{
"lol": "lurg"
}
]
}
```
#### `$ picnic some.json`
Output:
```sh
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:
```sh
eval $(picnic some.json)
```
### â Matching templates
Replace the values you want to extract with `$` variables:
#### `$ picnic some.json --match '{"boo": [$BAH, "lol": $LURG] }'`
Output:
```sh
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:
```sh
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:
```sh
$ ls /tmp
foo
baz.quz
boo.0
boo.1.lol
```
Outputs:
```sh
$ ./foo
bar
$ ./baz.quz
qork
$ ./boo.0
bah
$ ./boo.1.lol
lurg
```
### âŠī¸ Pipe stdin to picnic
```sh
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!