Shell config file parser (json, yaml)
Project description
# niet
[![Build Status](https://travis-ci.org/gr0und-s3ct0r/niet.svg?branch=devel)](https://travis-ci.org/gr0und-s3ct0r/niet)
![PyPI](https://img.shields.io/pypi/v/niet.svg)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/niet.svg)
![PyPI - Status](https://img.shields.io/pypi/status/niet.svg)
Get data from yaml file directly in your shell
## Install or Update niet
```sh
$ pip install -U niet
```
## Requirements
- Python 2.7+
## Usage
### With YAML file
Consider the yaml file with the following content:
```yaml
# /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:
```sh
$ 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:
```json
{
"project": {
"meta": {
"name": "my-project"
}
},
"foo": "bar",
"list-items": [
"item1",
"item2",
"item3"
]
}
```
You can retrieve data from this file by using niet like this:
```sh
$ 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:
```sh
PROJECT_NAME=$(niet your-file.yaml project.meta.name)
if [ "$?" = "1" ]; then
echo "Error occur ${PROJECT_NAME}"
else
echo "Project name: ${PROJECT_NAME}"
fi
```
## Examples
You can try niet by using the samples provided with the project sources code.
Sample example:
```yaml
# tests/samples/sample.yaml
project:
meta:
name: project-sample
tags:
- example
- sample
- for
- testing
- purpose
```
Retrieve the project name:
```sh
$ niet tests/samples/sample.yaml project.meta.name
project-sample
```
Deal with list of items
```sh
$ for el in $(niet tests/samples/sample.yaml project.meta.tags); do echo ${el}; done
example
sample
for
testing
purpose
```
## Tips
You can pass your search with or without quotes like this:
```sh
$ niet your-file.yaml project.meta.name
$ niet your-file.yaml "project.meta.name"
```
## Contribute
If you want to contribute to niet [please first read the contribution guidelines](CONTRIBUTING.md)
## Licence
This project is under the MIT License.
[See the license file for more details](LICENSE)
Hervé Beraud <herveberaud.pro@gmail.com>
[![Build Status](https://travis-ci.org/gr0und-s3ct0r/niet.svg?branch=devel)](https://travis-ci.org/gr0und-s3ct0r/niet)
![PyPI](https://img.shields.io/pypi/v/niet.svg)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/niet.svg)
![PyPI - Status](https://img.shields.io/pypi/status/niet.svg)
Get data from yaml file directly in your shell
## Install or Update niet
```sh
$ pip install -U niet
```
## Requirements
- Python 2.7+
## Usage
### With YAML file
Consider the yaml file with the following content:
```yaml
# /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:
```sh
$ 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:
```json
{
"project": {
"meta": {
"name": "my-project"
}
},
"foo": "bar",
"list-items": [
"item1",
"item2",
"item3"
]
}
```
You can retrieve data from this file by using niet like this:
```sh
$ 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:
```sh
PROJECT_NAME=$(niet your-file.yaml project.meta.name)
if [ "$?" = "1" ]; then
echo "Error occur ${PROJECT_NAME}"
else
echo "Project name: ${PROJECT_NAME}"
fi
```
## Examples
You can try niet by using the samples provided with the project sources code.
Sample example:
```yaml
# tests/samples/sample.yaml
project:
meta:
name: project-sample
tags:
- example
- sample
- for
- testing
- purpose
```
Retrieve the project name:
```sh
$ niet tests/samples/sample.yaml project.meta.name
project-sample
```
Deal with list of items
```sh
$ for el in $(niet tests/samples/sample.yaml project.meta.tags); do echo ${el}; done
example
sample
for
testing
purpose
```
## Tips
You can pass your search with or without quotes like this:
```sh
$ niet your-file.yaml project.meta.name
$ niet your-file.yaml "project.meta.name"
```
## Contribute
If you want to contribute to niet [please first read the contribution guidelines](CONTRIBUTING.md)
## Licence
This project is under the MIT License.
[See the license file for more details](LICENSE)
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
niet-1.1.0.tar.gz
(12.0 kB
view details)
Built Distribution
File details
Details for the file niet-1.1.0.tar.gz
.
File metadata
- Download URL: niet-1.1.0.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca149a0170615a85582da5d413c20090fc91e899fc3938f29aca276e4e86d1d7 |
|
MD5 | 15405ac2017c51cb86fa722be2ad252b |
|
BLAKE2b-256 | daab0f8602dd6c8e2bf849e333a44a5a198331b125e34bc98c6e4d3ce6b7917c |
File details
Details for the file niet-1.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: niet-1.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82ae88963013b0da9deccbc5b177ce55af7dbce785436ce65de421473119578c |
|
MD5 | e5a1364dbd787c12f0d5cccb48ff5303 |
|
BLAKE2b-256 | 0c09b18b0f0e5a6b2ade07fcc009cdb7b233f2ea509232041214ed690cd6aefd |