Gabriella439 / turtle

Shell programming, Haskell style
BSD 3-Clause "New" or "Revised" License
943 stars 90 forks source link

Support querying environment variable presence/absence #454

Open Gabriella439 opened 8 months ago

Gabriella439 commented 8 months ago

Fixes #452

Gabriella439 commented 8 months ago

I'm happy to add an "env" or something to the names to address (1) so I'll do that.

I'm a bit surprised about (2) because I had the opposite point of view (that isPresent / isAbsent were the footguns). The reason why is that treating an in-band value (the empty value) as a sentinel value that means unset is a common source of programming errors (not just in Bash, but in general). Like, in the case of a simple binary toggle this is less of a concern, but when the environment value stores an actual payload that the program will use then there is a greater risk that the payload can be meaningfully present, but empty.

9999years commented 8 months ago

Hmm, that's true. In my experience most environment variables are used for simple toggles. I would also expect the program to do some validation if the environment variable has semantics (e.g. check that a path exists if it's supposed to represent a path, etc.).