openuado / niet

Parse/Read yaml or json files directly in your shell (sh, bash, ksh, ...)
https://pypi.org/project/niet/
MIT License
39 stars 7 forks source link

Return empty value on error, not "Element not found" #30

Closed fvant closed 6 years ago

fvant commented 6 years ago

When an element is not present or empty, please return an empty string and not the actual error text.

Given the yaml

version: lab: 1.0.0 dev:

I would like both niet version.dev and niet version.prod to simply return an empty string.

The documentation gives a 'deal with errors' example but does that work ?

4383 commented 6 years ago

@fvant thanks for this issue.

Yep "deal with errors" example works!

I want to add an command line option that allow you to return empty string when an element is not present only (key not found).

When the key exist and the value are equal to empty then we will just return an empty value.

4383 commented 6 years ago

Fixed in the development version. It will be available on pypi inside the version 1.4.0 when we publish this version, that is to say, as soon as possible.

Example of use:

$ echo '{"foo": "bar"}' | niet fizz.goo --silent # with silent mode
$ echo $?
1
$ echo '{"foo": "bar"}' | niet fizz.goo # without silent mode 
Element not found: fizz.goo
$ echo $?
1

Have fun!

4383 commented 6 years ago

Well! Now Available on niet 1.4.0 This feature is now available on pypi! You can get it by updating niet:

pip install -U niet

Or by using the version 1.4.0:

pip install niet==1.4.0