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

Errors parsing yaml lists of dictionaries #81

Open sg3-141-592 opened 1 year ago

sg3-141-592 commented 1 year ago

Tested using niet ==3.2.0 and python 3.11.1

When trying to parse dictionaries that are in a list we get an error

niet -f eval . test.yaml
hello:
  world:
    - abc : 123
    - def : 456
Traceback (most recent call last):
  File "/workspace/.pyenv_mirror/user/3.11.1/bin/niet", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/workspace/.pyenv_mirror/user/current/lib/python3.11/site-packages/niet/__init__.py", line 287, in main
    print_result(result, out_format, in_format, search, out_file)
  File "/workspace/.pyenv_mirror/user/current/lib/python3.11/site-packages/niet/__init__.py", line 226, in print_result
    output = VALID_PRINTERS[out_format]["cmd"](res, search)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.pyenv_mirror/user/current/lib/python3.11/site-packages/niet/output.py", line 80, in print_eval
    results = _findevalitem(res, search)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.pyenv_mirror/user/current/lib/python3.11/site-packages/niet/output.py", line 64, in _findevalitem
    item = _findevalitem(v, k)
           ^^^^^^^^^^^^^^^^^^^
  File "/workspace/.pyenv_mirror/user/current/lib/python3.11/site-packages/niet/output.py", line 69, in _findevalitem
    el.append("{k}=( {value} )".format(k=k, value=" ".join(v)))
                                                  ^^^^^^^^^^^
4383 commented 10 months ago

Hello,

Thanks for reporting this issue and sorry for the late reply.

I think the error is related to the presence of the dash in lines with abc and def.

If I remove these dashes, then, the error disappear:

$ tox -r -e venv -- niet -f eval . /tmp/test.yaml
...
venv: commands[0]> niet -f eval . /tmp/test.yaml
hello__world__abc="123";hello__world__def="456"
.pkg: _exit> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True hatchling.build
  venv: OK (8.86=setup[8.76]+cmd[0.10] seconds)
  congratulations :) (8.99 seconds)

Is these dashes are mandatory?