Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support config values to have object types #42

Open
locallycompact opened this issue Jun 18, 2018 · 7 comments
Open

Support config values to have object types #42

locallycompact opened this issue Jun 18, 2018 · 7 comments

Comments

@locallycompact
Copy link
Contributor

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
Copy link
Owner

roman commented Jun 19, 2018

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
Copy link
Contributor Author

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
Copy link
Owner

roman commented Jun 20, 2018

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

@locallycompact
Copy link
Contributor Author

locallycompact commented Jun 20, 2018

0.4.0.3 I assume you mean, but yep

@roman
Copy link
Owner

roman commented Jun 20, 2018

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 roman changed the title Possible to support hashmaps as config types? Support config values to have object types Jun 20, 2018
@roman
Copy link
Owner

roman commented Jun 20, 2018

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants