dmulyalin / ttp

Template Text Parser
MIT License
351 stars 34 forks source link

Split string into list and loop over items #56

Closed draggeta closed 3 years ago

draggeta commented 3 years ago

I'm probably missing something, but I'm trying to parse ip name-server 10.0.0.10 10.0.0.11 10.0.0.12 10.0.0.13

into something similar to this:

{
  "server": [
    {
      "address": "10.0.0.10",
      "config": {
        "address": "10.0.0.10"
      }
    },
    {
      "address": "10.0.0.11",
      "config": {
        "address": "10.0.0.11"
      }
    },
    [...]
  ]
}

I just can't seem to find a way to iterate over the list I've created with

<group name='server*'>
ip name-server {{ address | ORPHRASE | split() }}
</group>

Is what I'm asking impossible or did I not read the documentation correctly?

dmulyalin commented 3 years ago

Hi,

There is no function in TTP that can do what you want, you need to have a look at using Python to process results and produce desired structure - you can do it using match variable, group or output macro or using some Python code that will invoke TTP and post-process results.

draggeta commented 3 years ago

Thank you for the quick reply. I thought that might be the case. I'll see if I can write macros then 👍