Shell config file parser (json, yaml)
Project description
# niet
Get data from yaml file directly in your shell
## Install
```sh
$ pip install niet
```
## Usage
### With YAML file
Consider the yaml file with the following content:
```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
```
## 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"
```
## Tests
```sh
niet tests/samples/samples.yaml project.meta.name
```
CHANGES
=======
0.1.0
-----
* First commit
Hervé Beraud <herveberaud.pro@gmail.com>
Get data from yaml file directly in your shell
## Install
```sh
$ pip install niet
```
## Usage
### With YAML file
Consider the yaml file with the following content:
```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
```
## 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"
```
## Tests
```sh
niet tests/samples/samples.yaml project.meta.name
```
CHANGES
=======
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
niet-0.1.0.tar.gz
(3.2 kB
view details)
Built Distribution
File details
Details for the file niet-0.1.0.tar.gz
.
File metadata
- Download URL: niet-0.1.0.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d71d296d109c696b2b95c8bd24cd850f2499048ea38590119485b2d6c1f6c804 |
|
MD5 | 25c0dd1d3e732cb2153927f4aa670b07 |
|
BLAKE2b-256 | 56bb0b5fa56d11c4a24214345506d8469c6c874f26b8d083a217bc60fe60e884 |
File details
Details for the file niet-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: niet-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbf56bb33d5fb1762866d30093fb5c2bbeb558764818fbad25972a859b091682 |
|
MD5 | 6fbc0edd24a4864a16afbfc9f38780e2 |
|
BLAKE2b-256 | 01c623528563225e60347bbe8a006dc5e77dda43094a37c305822c3051bbf4d7 |