LibreCat / Catmandu

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

Fix Catmandu::Fix::select is missing #369

Closed jorol closed 5 years ago

jorol commented 5 years ago
$ echo '{"foo":"bar"}' | catmandu convert JSON --fix 'if any_match(foo,bar) select() end'
Oops! Tried to execute the fix 'select' but can't find Catmandu::Fix::select on your system.
Error: No such fix package: select
Package name: Catmandu::Fix::select
Fix name: select
Source:
        if any_match(foo,bar) select() end

Catmandu::Fix::reject works:

$ echo '{"foo":"bar"}' | catmandu convert JSON --fix 'if any_match(foo,bar) reject() end'
[]
prod@b-app104:~/ZDB/script$
vpeil commented 5 years ago

I think the syntax is

select any_match(foo,bar)
reject any_match(foo,bar)

Don't know why reject works in the other syntax.

jorol commented 5 years ago

Yes, it works as condition, but sometime I want to do something like:

echo '{"foo":"bar"}' | catmandu convert JSON --fix 'if any_match(foo,'^b') if any_match(foo,'r$') select() end end'

It is also mentioned in the docs:

 ...
# Select all items 
select()
...
nics commented 5 years ago

unless foo() reject() end works. The inverse is a lot more difficult to implement and would imply some kind of program analysis.

jorol commented 5 years ago

Ok, I will fix the docs. Thanks.