Shell config file parser (json, yaml)
Project description
niet
Get data from yaml file directly in your shell
Install
$ pip install niet
Usage
With YAML file
Consider the yaml file with the following content:
# /path/to/your/file.yaml
project:
meta:
name: my-project
foo: bar
list-items:
- item1
- item2
- item3
You can retrieve data from this file by using niet like this:
$ niet /path/to/your/file.yaml "project.meta.name"
my-project
$ niet /path/to/your/file.yaml "project.foo"
bar
$ niet /path/to/your/file.yaml "project.list-items"
item1 item2 item3
$ # assign return value to shell variable
$ NAME=$(niet /path/to/your/file.yaml "project.meta.name")
$ echo $NAME
my-project
With JSON file
Consider the json file with the following content:
{
"project": {
"meta": {
"name": "my-project"
}
},
"foo": "bar",
"list-items": [
"item1",
"item2",
"item3"
]
}
You can retrieve data from this file by using niet like this:
$ niet /path/to/your/file.json "project.meta.name"
my-project
$ niet /path/to/your/file.json "project.foo"
bar
$ niet /path/to/your/file.json "project.list-items"
item1 item2 item3
$ # assign return value to shell variable
$ NAME=$(niet /path/to/your/file.json "project.meta.name")
$ echo $NAME
my-project
Deal with errors
When your JSON file content are not valid niet display an error and exit
with return code 1
You can easily protect your script like this:
PROJECT_NAME=$(niet your-file.yaml project.meta.name)
if [ "$?" = "1" ]; then
echo "Error occur ${PROJECT_NAME}"
else
echo "Project name: ${PROJECT_NAME}"
fi
Tips
You can pass your search with or without quotes like this:
$ niet your-file.yaml project.meta.name
$ niet your-file.yaml "project.meta.name"
Tests
You can try niet by using the samples provided with the project sources code.
Sample example:
# tests/samples/sample.yaml
project:
meta:
name: project-sample
tags:
- example
- sample
- for
- testing
- purpose
Retrieve the project name:
$ niet tests/samples/sample.yaml project.meta.name
project-sample
Deal with list of items
$ for el in $(niet tests/samples/sample.yaml project.meta.tags); do echo ${el}; done
example
sample
for
testing
purpose
CHANGES
- fix bad behavior on element not found
- fix documentation examples
- remove tick from list results
- using readme at markdown format on pypi
0.1.0
- First commit
Hervé Beraud herveberaud.pro@gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file niet-0.2.1.tar.gz
.
File metadata
- Download URL: niet-0.2.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f1c0303b5d1353ed6c5e9a5246b77c201de5b1aeb37db16417f8efac4e64ff8 |
|
MD5 | 9915a8f16c48606dcf4969664d8c3143 |
|
BLAKE2b-256 | 432fa546bf0f9cf237480e9b58d25f9aac49fa18001e016a7d42ee27c95c3d0f |
File details
Details for the file niet-0.2.1-py2.py3-none-any.whl
.
File metadata
- Download URL: niet-0.2.1-py2.py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1795c66df5598898b034b69a3bba13160e55a954b18466a69af13b0f85b537b9 |
|
MD5 | 9920e8b38afdcd144d091b7513423916 |
|
BLAKE2b-256 | f43dc2d663e38e23373519f063cffc126b3f9e88cbc966bf6fb97303255f1d14 |