LibreCat / Catmandu

Catmandu - a data processing toolkit
https://librecat.org
175 stars 31 forks source link

add fix 'env' #374

Closed vpeil closed 4 years ago

vpeil commented 4 years ago

Use case:

One has a fix file where one needs to add/change a field, e.g. adding a collection ID manually

This would require either changing the fix file every now and then or to follow the solution from https://librecatproject.wordpress.com/2015/05/20/preprocessing-catmandu-fixes/

Another option would be to use ENV variables:

$ ENV_MYVAL=bar catmandu convert Null to YAML --fix "env(foo, ENV_MYVAL)"

I find it quite handy, please have a look if this is useful for the rest of you.

coveralls commented 4 years ago

Coverage Status

Coverage increased (+0.02%) to 89.377% when pulling b1f60069c1ae5a9826edee4562399375c3faef2a on pr/env_fix into d018e790f3690c3593fc56f5806bea8cd17a43c1 on dev.

nics commented 4 years ago

The blog post is outdated, fixes already have a preprocessing mechanism: https://metacpan.org/pod/Catmandu::Fix#preprocess The command line tools also support this.

phochste commented 4 years ago

@nics can you add an example in the synopsis how this preprocessing/variables is used on the command line. I myself always need to find my way in the docs how to do this

nics commented 4 years ago

added examples here: https://github.com/LibreCat/Catmandu/blob/dev/lib/Catmandu/Fix.pm

vpeil commented 4 years ago

ah great! the example with the preprocess is exactly what I need. Thanks!

No need for this PR then.