MaxKellermann/ferm

Flattening arrays

Closed this issue · 2 comments

I have some variables containing multiple networks like (10.0.0.0/8 192.168.0.0/16).
I'd like to run a hook with this variable as argument, but hooks only allow string variable.
Is there a way to flatten arrays? I tried @cat without success so far…

I don't understand what you're trying to do, but it looks like "array flattening" is not what you want. You rather want to convert an array into a string. Which is what @cat can do. But I don't know how this was unsuccessful. Maybe describe some more context of your problem, and how @cat failed.

Here are two attempts for what I need:

> cat test_ferm.conf 
@def $MY_ARRAY = (127.0.0.1 10.0.0.1);

@hook post "/usr/local/bin/after_ferm @cat($MY_ARRAY)";

> ferm --slow --noexec --lines test_ferm.conf 
Error in test_ferm.conf line 3:
@hook post "/usr/local/bin/after_ferm @cat($MY_ARRAY)" <--
variable 'MY_ARRAY' must be a string, but it is an array

> cat test_ferm2.conf 
@def $MY_ARRAY = (127.0.0.1 10.0.0.1);

@def $MY_STRING = @cat($MY_ARRAY);

> ferm --slow --noexec --lines test_ferm2.conf 
Error in test_ferm2.conf line 3:
@def $ MY_STRING = @cat 
( 
    $ MY_ARRAY 
) 
<--
String expected