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

Niet says a key is missing when its value is falsey #72

Closed Ssloto closed 2 years ago

Ssloto commented 2 years ago

If I have a YAML file, e.g. with the parameters:

foo: false
bar: null

Then I get the following error when I try to access foo or bar on the CLI

niet ".bar" test-config.yaml
Element not found: bar

The same yaml file will return a value for the same parameters if the value is 'true.'

It would be nice to instead return the value corresponding to the key, which would be null or false. I am using niet v2.4.0.

Ssloto commented 2 years ago

Just realized it also does this when an int is set to 0

4383 commented 2 years ago

Hello,

Thanks for the heads up. Indeed it's not what is expected in this kind of situation, I'll have a look ASAP.

If you've spare time then feel free to propose a pull request to fix this behaviour.

4383 commented 2 years ago

First, sorry for my late reply. I'm able to reproduce your issue.

Indeed it would be preferable to return the value instead of raising this message. I think its a side effect of the lib we use to parse data.

4383 commented 2 years ago

Will be fixed in the next release by https://github.com/openuado/niet/commit/11df54ac9245fa9cd7ef1b13e0fea4e4432cc651

Unfortunately this patch only fix keys equal to False and 0. By default, the lib we use to parse the data return None when an element is not found, so we are not able to differentiate an element not found and something that is set to Null.

I'll try to see if we have an other way to capture the null values.