Skip to content

Commit

Permalink
Merge pull request #139 from ruurtjan/137-support-absolute-paths
Browse files Browse the repository at this point in the history
#137 Add support for absolute paths
  • Loading branch information
Philippus authored Apr 12, 2022
2 parents 79feec0 + 0beda6b commit c4be8b9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ MY_CERT="-----BEGIN CERTIFICATE-----
Variable expansion of the form `$FOO` and `${FOO}` is supported based on the values in `.env` or the system environment.

### Change file name
It is possible to change the file name `.env`
It is possible to override the default file name `.env`. It will be treated as an absolute path if it starts with a `/`, and as a relative path to base directory of this project otherwise.
```
ThisBuild / envFileName := "dotenv"
```
Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/au/com/onegeek/sbtdotenv/SbtDotenv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ object SbtDotenv extends AutoPlugin {
fileName: String
): Option[Map[String, String]] = {
val baseDirectory = state.configuration.baseDirectory
val filePath = if (fileName.startsWith("/")) fileName else s"${baseDirectory}/${fileName}"
state.log.debug(s"Base directory: ${baseDirectory}")
state.log.debug(s"looking for .env file: ${baseDirectory}/${fileName}")
val dotEnvFile: File = new File(s"${baseDirectory}/${fileName}")
state.log.debug(s"looking for .env file: ${filePath}")
val dotEnvFile: File = new File(filePath)
parseFile(dotEnvFile).map { environment =>
state.log.info(
s".env detected (fileName=${fileName}). About to configure JVM System Environment with new map"
Expand Down

0 comments on commit c4be8b9

Please sign in to comment.