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

Ability to make hooks be a static type #186

Open robcxyz opened 10 months ago

robcxyz commented 10 months ago

Hook's are basically structs with methods but it would be really helpful if the hook could also be a static type. For instance:

MyType<-:
  type: str 
  validator: 
     return->: v --if "v in ['foo','bar']"

MyHook: 
  foo: MyHookType

Here we see a hook which is just a string and has a validator to go with. In this case, we can't have extra fields as then a field named type would be mangled as some type hook. Should also qualify the default of type as again, the user might have a hook which has a single type field which might have some default that makes no sense and the intention is again some map that has a key with a default type looking value.

This needs to be done with some typing_extensions.Annotated use where we are really just creating some validator I think.