roman / Haskell-etc

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

Support config values to have object types #42

Open locallycompact opened 6 years ago

locallycompact commented 6 years ago

Hi, I'd like to be able to do something like

aliases:
  etc/spec:
    type: "object"
    cli:
      commands:
      - foo

Where aliases is an object in the aeson sense - a hashmap that may change between configurations. It is naturally impractical to supply an hashmap via environment variable or command line so this would be file config only. Any thoughts?

roman commented 6 years ago

It is naturally impractical to supply a hashmap via environment variable or command line so this would be file config only. Any thoughts?

That's correct, not sure if we fail when specifying an env or a cli entry when the type is object, I think we should.

So, you want the entry to be defined in the file configuration map only if the command is foo?

The cli.command setting does not do any enforcement, it's data is used to generate the CLI command of your program.

I think you can do a type: "object" without the cli and it should work. Is it not the case?

locallycompact commented 6 years ago

If I just do

aliases:
  etc/spec:
    type: "object"

I get the error

InvalidConfiguration Nothing "Error in $['etc/entries'].aliases.type: expected ConfigValueType (string, number, bool), encountered String"
roman commented 6 years ago

Wondering what version of etc are you using, is it 0.4.3.0?

locallycompact commented 6 years ago

0.4.0.3 I assume you mean, but yep

roman commented 6 years ago

Ok, after going through the code and understanding what is going on, I came to the fact that I did not add this functionality on purpose, given that I always wanted my objects to have a shape on configuration definition.

I added the possibility to have an array of objects as a type (e.g. [object]), because I needed a list of objects, but didn't go through the single object definition.

This is a missing feature that needs to be added.

Requirements

roman commented 6 years ago

I'll be able to get to this over the weekend, if you feel like you want to tackle it, that would be awesome, I can tell you everything start with changes here

locallycompact commented 6 years ago

Thanks, I had an attempt but it's not clear to me what else I'm supposed to change.