Skip to content

Commit

Permalink
import godotenv as a subpackage
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Jan 3, 2022
1 parent 91ed80f commit 376d88f
Show file tree
Hide file tree
Showing 20 changed files with 1,296 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cli/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
"regexp"
"strings"

"github.com/compose-spec/compose-go/dotenv"
"github.com/compose-spec/compose-go/errdefs"
"github.com/compose-spec/compose-go/loader"
"github.com/compose-spec/compose-go/types"
"github.com/compose-spec/godotenv"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -220,7 +220,7 @@ func WithDotEnv(o *ProjectOptions) error {
defer file.Close()

notInEnvSet := make(map[string]interface{})
env, err := godotenv.ParseWithLookup(file, func(k string) (string, bool) {
env, err := dotenv.ParseWithLookup(file, func(k string) (string, bool) {
v, ok := os.LookupEnv(k)
if !ok {
notInEnvSet[k] = nil
Expand Down
22 changes: 22 additions & 0 deletions dotenv/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2013 John Barton

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 2 additions & 0 deletions dotenv/fixtures/equals.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export OPTION_A='postgres://localhost:5432/database?sslmode=disable'

2 changes: 2 additions & 0 deletions dotenv/fixtures/exported.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export OPTION_A=2
export OPTION_B='\n'
3 changes: 3 additions & 0 deletions dotenv/fixtures/inherited-multi-var.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
foo=bar
VAR_TO_BE_LOADED_FROM_OS_ENV
bar=baz
1 change: 1 addition & 0 deletions dotenv/fixtures/inherited-not-found.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VARIABLE_NOT_FOUND
1 change: 1 addition & 0 deletions dotenv/fixtures/inherited-single-var.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VAR_TO_BE_LOADED_FROM_OS_ENV
2 changes: 2 additions & 0 deletions dotenv/fixtures/invalid1.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INVALID LINE
foo=bar
7 changes: 7 additions & 0 deletions dotenv/fixtures/plain.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
OPTION_A=1
OPTION_B=2
OPTION_C= 3
OPTION_D =4
OPTION_E = 5
OPTION_F =
OPTION_G=
14 changes: 14 additions & 0 deletions dotenv/fixtures/quoted.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
OPTION_A='1'
OPTION_B='2'
OPTION_C=''
OPTION_D='\n'
OPTION_E="1"
OPTION_F="2"
OPTION_G=""
OPTION_H="\n"
OPTION_I = "echo 'asd'"
OPTION_J = 'first line
second line
third line
and so on'
OPTION_Z = "last value"
5 changes: 5 additions & 0 deletions dotenv/fixtures/substitutions.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
OPTION_A=1
OPTION_B=${OPTION_A}
OPTION_C=$OPTION_B
OPTION_D=${OPTION_A}${OPTION_B}
OPTION_E=${OPTION_NOT_DEFINED}
5 changes: 5 additions & 0 deletions dotenv/fixtures/unquoted.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
OPTION_A = "some quoted phrase"
OPTION_B=first one with an unquoted phrase
OPTION_C = then another one with an unquoted phrase
OPTION_D = then another one with an unquoted phrase special è char
OPTION_E = "then another one quoted phrase"
Loading

0 comments on commit 376d88f

Please sign in to comment.