Add getenv_strict variant
Hi! I often find the getenv ppx very useful, but one thing that is missing from it is the ability to statically fail when the environment variable is not set.
This implements a new extension getenv_strict that encountering a missing environment variable will fail with:
File "src_test/test_ppx_getenv.ml", line 5, characters 36-55:
5 | assert_equal "42" [%getenv_strict "PPX_GETENV_CHECK_MISSING"]
^^^^^^^^^^^^^^^^^^^^^^^^^
Error: [%getenv_strict] not set: PPX_GETENV_CHECK_MISSING
If you think this is a good addition, I'm happy to document this in the README and add a test case.
If you think this is a good addition, I'm happy to document this in the README and add a test case.
sorry for the lack of feedback. Yes i personally think it's a good addition. If you could add these i should be able to merge and make a release
Thanks for looking into this @kit-ty-kate! I was just thinking about this PR last week and remembered it could be useful to also have a variant that uses a default value if the var lookup fails.
Maybe we could do something like this?
[%getenv "SOMETHING" {default="foo"}]
[%getenv "SOMETHING" {strict=true}]
Not sure if this is the most appropriate syntax. Let me know what you think.
The syntax looks good. The default option sounds nice, maybe it could take either a string or None, in the latter case it would have the same behaviour as Sys.getenv_opt
Great, I'll try to get this done soon.