peterbourgon / ff

Flags-first package for configuration
Apache License 2.0
1.34k stars 59 forks source link

Env var split with escape character ? #127

Closed sentriz closed 5 months ago

sentriz commented 6 months ago

hi! thanks for ff, i've been using it for gonic for years

there was a user today with an env var such as GONIC_MPV_ARGS="--audio-device=alsa/iec958:CARD=ta,DEV=0"

which resulting in an unwanted split. i know it can turned off or change the delimiter, but gonic does use the comma splitting for other flags already

i wonder is it feasible to comma escape the demilimiter like a\,b?

thanks!

peterbourgon commented 6 months ago

Just to be clear, you're using ff.WithEnvVarSplit(",")?

sentriz commented 6 months ago

I'm still on v1 actually but yes that's the idea. I was hoping it would be possible to escape the env var split delim

peterbourgon commented 6 months ago

I think I understand, but just so there's no ambiguity, can you provide a complete example?

sentriz commented 6 months ago

sure, for example a docker-compose env, someone may have

environment:
  - GONIC_MUSIC_PATHS="/a,/b"
  - GONIC_MPV_DEVICE="iec958:CARD=ta,DEV=0"

the first is correctly parsed as []string{"/a", "/b"}, but the second is parsed as []string{"iec958:CARD=ta", "DEV=0"} which in this case is not desired

i'm wondering if it makes sense to provide (or automatically) accept an escape character for the delimiter such as \, so that iec958:CARD=ta\,DEV=0 could be parsed as []string{"iec958:CARD=ta,DEV=0"} without an split

peterbourgon commented 6 months ago

Escaping isn't the path forward here — instead, call ff.WithEnvVarSplit with a different delimiter character, which is never valid in an env var value. For example · or or etc.

sentriz commented 6 months ago

the trouble is that is global to the whole flag set, i need the delimiter to be , for some flags such GONIC_MUSIC_PATHS above

i suppose if i had the hindsight i would have used a more obscure delimiter, but now there are potentially 1000s of gonic configs around the world using ,

sentriz commented 5 months ago

thank you!