envsub
envsub copied to clipboard
Allow defaults for undefined variables
Would it be possible to allow a default value to be specified for undefined env vars? I've used envtpl before, which has this feature, and it was really useful. I'm not sure what it would look like here, but here's how envtpl does it:
{{ MY_VAR | default(3) }}
Thanks for this awesome module!
You can provide defaults either using an env file:
envsub --env-file envFile.env templateFile (provide defaults in envFile - see docs)
or on the CLI
envsub --env MYVAR1 --env MYVAR2=station templateFile outputFile (here MYVAR2 has a default)
envsub does not support providing defaults in the templateFile itself - its not popular enough for me to put the effort in - all the best :)
You might consider using envsubh which allows this (but does not afford the tight control provided by envsub) - envsubh is installed automatically when you install envsub - see the docs
Now that this module is more popular, I am willing to put the effort in to fix this. However, I only plan to do so if there is more demand.
Does anyone else want this fixed? If so let me know and I will crack on with it.
Leaving open for now.
+1
+1
+1
+1
Hi @danday74 , thank you for this cool package. Do you think there is any chance to have this default value feature implemented? Our software build now strongly depends now on your library and we would love to see a feature like this implemented! How many upvote would you need? :P Maybe I could help in the implementation if you think there are parts which can be done separately!
Please let me know!
Kind regs, Andras Popovics
+1
@popovicsandras - I apologise but I am just about to start a new contract and need to focus my attention there. However, if you raise a PR I will give it a manual check and then merge it if the tests are passing.