loganasherjones / yapconf

Yet Another Python Configuration
http://yapconf.readthedocs.io/en/stable/
MIT License
18 stars 4 forks source link

Environment names with prefix #11

Closed hazmat345 closed 6 years ago

hazmat345 commented 6 years ago

I was trying to use a config option with the name bg_host and a specification with the environment prefix BG_.

I expected to need to set the environment variable named BG_BG_HOST for yapconf to work correctly. That was successful.

That looks a little weird to me, so I set the env_name option in the spec to HOST, expecting that then setting the BG_HOST environment variable would work, but it didn't.

Looking though the code it looks like if you specify an alternate environment name the prefix doesn't get applied to it. I can see certain situations where that would be preferable, but in my case I'd like the prefix to still be applied to the new name.

I worked around the issue by setting the env_name to BG_HOST and that worked like I wanted, but that requires knowing at spec creation time what prefix I'm planning on applying.

I kind of expected the prefix to be applied to the new name, so I'm wondering if that should be the default behavior. Perhaps with a little flag like apply_prefix that could be set to False if you didn't want that behavior?

loganasherjones commented 6 years ago

I agree, this is a bit weird. I do think the apply_prefix option needs to be changed to something like apply_prefixes and instead of it being a flag, it should be an array of prefixes to apply. If we are going to add this option, it also makes sense to add the same formatting options to the CLI.