TheNeikos / envious

Deserialize (potentially nested) environment variables into your custom structs
Apache License 2.0
60 stars 2 forks source link

Case insensitive parsing #17

Closed tenuous-guidance closed 1 year ago

tenuous-guidance commented 1 year ago

The standard for shell variables is pretty uniformly that anything exported is in SCREAMING_SNAKE_CASE. Currently this isn't possible to parse with envious unless it's changed for all methods of parsing the structures with serde (as serde doesn't allow re-casing as a per-source choice). Would you be open to adding a parsing option that loads variables case insensitively? I realise this can result in ambiguous parsing if users of envious have multiple fields with the same spelling but different capitalisation, but that seems like an odd choice and can be a documented limitation.

I'm happy to raise an MR for the work if you're open to the suggestion, but wanted to run it by you first and maybe discuss your preferences on what the API would look like.

TheNeikos commented 1 year ago

Thank you for the idea!

I would be fine with it.

Things that would be important:

I would gladly accept a MR!

tenuous-guidance commented 1 year ago

Right now, envious is used via envious::from_env(envious::Prefix::None) or similar calls. I'm thinking of having the equivalent command be envious::Config::default().from_env(). The Config would use the builder pattern, so you might instead have: envious::Config::default().with_prefix("PREFIX").case_sensitive(false).from_slice(&[])

TheNeikos commented 1 year ago

Yeah that approach seems good to me