roman / Haskell-etc

Declarative configuration spec for Haskell projects
MIT License
47 stars 7 forks source link

Basic config value validation #62

Open lehins opened 6 years ago

lehins commented 6 years ago

This is just an idea, but it could be valuable. Have a small collection of declarative validators that can be specified directly in the spec. Validators are simply functions that evaluate to Bool and are applied to the value that was parsed successfully. For example range or compare for numbers and other Ord things, length for strings and lists, eg:

    port:
      etc/spec:
        default: 3000
        type: number
        validators:
        - lte:
            value: 0
            error: "Ports with non-positive values don't make sense"
        - gt:
            value: 65535
            error: "Port numbers are 16-bit"
        - lt:
            value: 1024
            warn: "Using system level port, root privilege will be necessary"