sudoblockio / tackle

Tackle is a programmable configuration language for building modular utilities, code generators, and CLIs with schema validation baked in.
Apache License 2.0
52 stars 2 forks source link

Add variadic input args #183

Open robcxyz opened 10 months ago

robcxyz commented 10 months ago

Right now we don't have a way to have variadic input args. For instance:

class ConcatenateHook(BaseHook):
    hook_name: str = 'concat'
    src: list = Field(
        ...,
        description="A list to concatenate the items of.",
        render_by_default=True,
    )

    args: list = ['src']

    def exec(self) -> list:

Here we expect a string reference to an arg and any additional args are just joined into a list but this is not really what you want when concatting lists since you might want to render individual strings before joining them together. Instead you want a variadic which will take in any number of input args, rendering the strings and then joining them.

Would require changes to the parser as the render_by_default field level definition is processed there before the joining of the args. Might be a little too complicated to implement as we'd be having to check the Hook's arg field before doing the rendering.

This will take a little thinking but we should be able to do something like:

args: list = ['src', '...']

To indicate that there is any number of args which will get mapped to src.

The input could then be:

out->: concat list_1 list_2

Instead of:

out->: concat {{list_1}} {{list_2}}

This is kind of dumb as maybe you simply want list_1list_2 but that is what join hook is for.