Haskell-etc icon indicating copy to clipboard operation
Haskell-etc copied to clipboard

Support config values to have object types

Open locallycompact opened this issue 7 years ago • 7 comments

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?

locallycompact avatar Jun 18 '18 12:06 locallycompact

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?

roman avatar Jun 19 '18 17:06 roman

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"

locallycompact avatar Jun 20 '18 10:06 locallycompact

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

roman avatar Jun 20 '18 13:06 roman

0.4.0.3 I assume you mean, but yep

locallycompact avatar Jun 20 '18 13:06 locallycompact

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

  • Allow the type: object in etc
  • Make sure that the parser fails when having a type: object when cli or env options are given (as there is no sensitive way to get this values from those inputs)
  • Tests that validate functionality in the SpecTest.hs file

roman avatar Jun 20 '18 15:06 roman

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

roman avatar Jun 20 '18 15:06 roman

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

locallycompact avatar Jul 02 '18 13:07 locallycompact