packages feed

dotenv 0.10.1.0 → 0.11.0.0

raw patch · 6 files changed

+43/−10 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,4 +1,9 @@ ## MASTER+## Dotenv 0.11.0.0+### Modified (Breaking change - new behavior)+* Take last rather than first env var in dotenv file (reported by @rudymatela and+solved by @anddriex). This will be the default behavior for the CLI, too.+ ## Dotenv 0.10.1.0 ### Added * Short `-x` for `--example` flag
README.md view
@@ -102,7 +102,8 @@ when loading the envs. A `True` means that Dotenv will print a message when a variable is loaded.  A `False` on `allowDuplicates` means that Dotenv will not allow duplicate keys, and instead it will throw-an error. A `True` means that Dotenv will allow duplicate keys, and it will use the first one if,`configOverride` is not set to `True`.+an error. A `True` means that Dotenv will allow duplicate keys, and it will use the last one defined in the file (default behavior).+ ### Advanced Dotenv File Syntax  You can add comments to your Dotenv file, on separate lines or after
dotenv.cabal view
@@ -1,5 +1,5 @@ name:                dotenv-version:             0.10.1.0+version:             0.11.0.0 synopsis:            Loads environment variables from dotenv files homepage:            https://github.com/stackbuilders/dotenv-hs description:@@ -48,6 +48,7 @@ data-files:   .dotenv   .dotenv.example+  .dotenv.dup  flag static   description:        Creates static binary.
spec/Configuration/DotenvSpec.hs view
@@ -43,6 +43,15 @@        lookupEnv "foo" `shouldReturn` Just "new setting" +    it "loads the last set value in config list with duplicates" $ do+      lookupEnv "foo" `shouldReturn` Nothing+      lookupEnv "bar" `shouldReturn` Nothing++      load False [("foo", "first"), ("bar", "second"), ("foo", "third")]++      lookupEnv "foo" `shouldReturn` Just "third"+      lookupEnv "bar" `shouldReturn` Just "second"+   describe "loadFile" $ before_ setupEnv $ after_ clearEnvs $  do     it "loads the configuration options to the environment from a file" $ do       lookupEnv "DOTENV" `shouldReturn` Nothing@@ -64,6 +73,15 @@       loadFile sampleConfig { configOverride = True }        lookupEnv "DOTENV" `shouldReturn` Just "true"++    it "loads the last set value in dotenv file with duplicates" $ do+      lookupEnv "FOO" `shouldReturn` Nothing+      lookupEnv "BAR" `shouldReturn` Nothing++      loadFile (Config ["spec/fixtures/.dotenv.dup"] [] False False True)++      lookupEnv "FOO" `shouldReturn` Just "last"+      lookupEnv "BAR" `shouldReturn` Just "tender"      context "when the .env.example is present" $ do       let config = sampleConfig { configExamplePath = ["spec/fixtures/.dotenv.example"]}
+ spec/fixtures/.dotenv.dup view
@@ -0,0 +1,3 @@+FOO=first+BAR=tender+FOO=last
src/Configuration/Dotenv.hs view
@@ -24,17 +24,19 @@                                                       setEnv) import           Configuration.Dotenv.Parse          (configParser) import           Configuration.Dotenv.ParsedVariable (interpolateParsedVariables)-import           Configuration.Dotenv.Types          (Config (..), defaultConfig)-import           Control.Monad.Trans                 (lift)-import           Control.Monad.Reader                (ReaderT, ask, runReaderT)+import           Configuration.Dotenv.Types          (Config (..),+                                                      defaultConfig) import           Control.Exception                   (throw) import           Control.Monad                       (unless, when) import           Control.Monad.Catch import           Control.Monad.IO.Class              (MonadIO (..))+import           Control.Monad.Reader                (ReaderT, ask, runReaderT)+import           Control.Monad.Trans                 (lift) import           Data.Function                       (on)-import           Data.List.NonEmpty                  (NonEmpty(..))-import qualified Data.List.NonEmpty as NE-import           Data.List                           ((\\), intercalate, union)+import           Data.List                           (intercalate, union, (\\))+import           Data.List.NonEmpty                  (NonEmpty (..))+import qualified Data.List.NonEmpty                  as NE+import           Data.Map                            (fromList, toList) import           System.IO.Error                     (isDoesNotExistError) import           Text.Megaparsec                     (errorBundlePretty, parse) @@ -49,7 +51,7 @@   -> [(String, String)] -- ^ List of values to be set in environment   -> m () load override kv =-  runReaderT (mapM_ applySetting kv) defaultConfig {configOverride = override}+  runReaderT (mapM_ applySetting (nubByLastVar kv)) defaultConfig {configOverride = override}  -- | @loadFile@ parses the environment variables defined in the dotenv example -- file and checks if they are defined in the dotenv file or in the environment.@@ -86,7 +88,7 @@             ]    unless allowDuplicates $ (lookUpDuplicates . map fst) vars-  runReaderT (mapM_ applySetting vars) config+  runReaderT (mapM_ applySetting (nubByLastVar vars)) config  where   showPaths :: String -> NonEmpty FilePath -> String   showPaths _ (p:|[]) = p@@ -156,3 +158,6 @@   if x `elem` xs     then forbidDuplicates x     else lookUpDuplicates xs++nubByLastVar :: [(String, String)] -> [(String, String)]+nubByLastVar = toList . fromList