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:
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
0.1.1
- 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.0.tar.gz
.
File metadata
- Download URL: niet-0.2.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5142210425fbfc3a0a6792acf2f37eda8fb8404d3adaf51498320def79cbcbcd |
|
MD5 | 594c085e85b0849ca78151daffe26546 |
|
BLAKE2b-256 | 639f97438c18be84c6e642c961de9918b4d4ee2ecf388224951049648e363c3e |
File details
Details for the file niet-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: niet-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8888c6247d44b318ee5980b91e012ddfd21f2df400ec1616cf70d6b343ac3371 |
|
MD5 | 2b3adacb7ca3411db2dddcbe364e77be |
|
BLAKE2b-256 | b05b25324e906dbbd106e55359621070a97521878c8565bb39719b9279842476 |