danday74 / envsub

NPM - envsub is envsubst for Node.js
Other
62 stars 10 forks source link

Allow defaults for undefined variables #8

Open knackjason opened 5 years ago

knackjason commented 5 years ago

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!

danday74 commented 5 years ago

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

danday74 commented 4 years ago

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.

knackbkalb commented 4 years ago

+1

knackjax commented 4 years ago

+1

pmartinezga commented 3 years ago

+1

popovicsandras commented 3 years ago

+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

mauriziovitale commented 3 years ago

+1

danday74 commented 3 years ago

@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.