envsub icon indicating copy to clipboard operation
envsub copied to clipboard

Allow defaults for undefined variables

Open knackjason opened this issue 6 years ago • 8 comments

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!

knackjason avatar Feb 20 '19 21:02 knackjason

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 avatar Feb 21 '19 05:02 danday74

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.

danday74 avatar Dec 01 '19 08:12 danday74

+1

knackbkalb avatar Jan 17 '20 17:01 knackbkalb

+1

knackjax avatar Jan 17 '20 17:01 knackjax

+1

pmartinezga avatar May 19 '21 15:05 pmartinezga

+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

popovicsandras avatar Jun 20 '21 22:06 popovicsandras

+1

mauriziovitale avatar Jun 21 '21 08:06 mauriziovitale

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

danday74 avatar Jun 21 '21 10:06 danday74