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
51 stars 2 forks source link

Hook Field Defaults #237

Open robcxyz opened 8 months ago

robcxyz commented 8 months ago

Hook Field Defaults

Allow flexible ways to declare hook field defaults

Overview

Declarative hook default values should be parsed for hook calls.


<-:

  literal: val

  literal_compact->: input

  literal_expanded:

    ->: input

  field:

    type: str

    default: foo

  field_default_compact:

    type: str

    default->: input  

  field_default_expanded:

    type: str

    default:

      ->: input

Ways to implement

  1. Macro + type handler

    • Rewrites the input in expanded form

    • When 'default' key is a dict, create a special dict type that can be parsed later in the absense of a supplied input.

    • Can't parse right away as we don't know if this is a user supplied variable

    • Don't know the type either so it either needs to be supplied (normally with default key, you don't need to give type) or it is set as Any until the default dict is parsed.

    • Needs to be done when we compile the hook


<-:

  # from

  literal_compact->: input

  # to

  literal_compact:

    default:

      ->: input

  # from

  literal_expanded:

    ->: input

  # to

  literal_expand:

    default:

      ->: input

  # This is an issue because the default has no type

  # from

  field_default_compact:

    type: str

    default->: input  

  # to

  field_default_compact2:

    type: str

    default:  

      ->: input

Calling tackle externally

Issues

  1. For the prompt hooks, the msg without the message field is the key which in this case the default, not what we want

This is probably not an issue as the default is just the key that refs the value. Not the key that is actually in the dict