Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added global substitutions support #72

Closed
wants to merge 1 commit into from
Closed

Conversation

arsoba
Copy link

@arsoba arsoba commented Feb 26, 2019

Hi,
I've added support for substitutions for global env vars.

@davidkarlsen
Copy link

@joho ping?

@davidkarlsen
Copy link

@arsoba PTAL?

@ebudan
Copy link

ebudan commented Feb 11, 2020

Seconding the need for this fix.

I also notice a slight tweak that I'd consider necessary: this fix does not work intuitively with the Overload() vs. Load() paradigm: Load() will not override variables defined previously in the file, but will override those inherited from os environment. The overload flag would have to be propagated to expandVariables() and the os/file value returned accordingly where this fix was made.

@fabriciojs
Copy link

Just FYI yesterday I created issue #102 and then implemented https://github.com/joho/godotenv/pull/103/files which holds the same feature here but already considering the comment @ebudan added, passing through the overload flag to the expansion function.

@luisdavim
Copy link

@ebudan @fabriciojs I don't think we need to care about load vs overload here, that's handled after in the loadFile function.

@joho why is a custom function needed for expanding variables? Why not just use os.ExpandEnv? If the reason is to support the $(VAR) format, I think there's a (\))? missing at the end of the regex.

if val, ok := m[submatch[4]]; ok {
return val
}
return os.Getenv(submatch[4])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return os.Getenv(submatch[4])
if val, ok := os.LookupEnv(submatch[4]); ok {
return val
}

nit: this way if the variable is not defined yet it will remain unexpanded allowing that case to be handeld by the code using this lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants