packages feed

dotenv 0.7.0.0 → 0.8.0.0

raw patch · 9 files changed

+61/−43 lines, 9 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Configuration.Dotenv.Environment: getEnvironment :: IO [(String, String)]
+ Configuration.Dotenv.Environment: lookupEnv :: String -> IO (Maybe String)
+ Configuration.Dotenv.Environment: setEnv :: String -> String -> IO ()
+ Configuration.Dotenv.Environment: unsetEnv :: String -> IO ()

Files

CHANGELOG.md view
@@ -1,4 +1,9 @@ ## MASTER+## Dotenv 0.8.0.0+* Add `Configuration.Dotenv.Environment` module exporting functions from `System.Environment`,+  `System.Environment.Compat`, or `System.Environment.Blank`, depending on `base` version.+* Add support for blank environment variables for `base` >= 4.11.0.0.+ ## Dotenv 0.7.0.0 * Hide helper modules in other-modules 
README.md view
@@ -40,24 +40,11 @@ ```  After calling `Dotenv.load`, you are able to read the values set in your-environment using standard functions from `System.Environment` such as-`lookupEnv` and `getEnv`.--### NOTE: Empty environment variables--If you need to have empty environment variables in your configuration, you can-use something like the code below:--```haskell-fromMaybe "" <$> lookupEnv "ENV_VAR"-```+environment using standard functions from `System.Environment` or+`System.Environment.Blank` (`base` >= 4.11.0.0), such as `getEnv`. -Currently, `dotenv-hs` doesn't allow you to set empty environment variables,-because of [setEnv](https://hackage.haskell.org/package/base-4.9.1.0/docs/System-Environment.html#v:setEnv)-from our `System.Environment`. This is bug reported in [GHC ticket](https://ghc.haskell.org/trac/ghc/ticket/12494).-We have had many [dicussions](https://github.com/stackbuilders/dotenv-hs/issues/48)-about this. Fortunately, there is already some work for this issue in-[GHC Phabricator](https://phabricator.haskell.org/D3726).+If your version of `base` is < 4.11.0.0, then setting an environment variable value to+a blank string will remove the variable from the environment entirely.  ### Variable substitution 
dotenv.cabal view
@@ -1,5 +1,5 @@ name:                dotenv-version:             0.7.0.0+version:             0.8.0.0 synopsis:            Loads environment variables from dotenv files homepage:            https://github.com/stackbuilders/dotenv-hs description:@@ -78,6 +78,7 @@  library   exposed-modules:      Configuration.Dotenv+                      , Configuration.Dotenv.Environment   other-modules:        Configuration.Dotenv.Parse                       , Configuration.Dotenv.ParsedVariable                       , Configuration.Dotenv.Text@@ -117,6 +118,7 @@                        , Configuration.Dotenv.TextSpec                        , Configuration.Dotenv.ParseSpec                        , Configuration.Dotenv+                       , Configuration.Dotenv.Environment                        , Configuration.Dotenv.Text                        , Configuration.Dotenv.Types                        , Configuration.Dotenv.Parse
spec/Configuration/Dotenv/TextSpec.hs view
@@ -1,20 +1,12 @@-{-# LANGUAGE CPP #-}- module Configuration.Dotenv.TextSpec (main, spec) where  import Configuration.Dotenv.Text (parseFile)+import Configuration.Dotenv.Environment (lookupEnv, unsetEnv)  import Test.Hspec  import Control.Monad (liftM)-import System.Environment (lookupEnv) import qualified Data.Text as T--#if MIN_VERSION_base(4,7,0)-import System.Environment (unsetEnv)-#else-import System.Environment.Compat (unsetEnv)-#endif  {-# ANN module ("HLint: ignore Reduce duplication" :: String) #-} 
spec/Configuration/DotenvSpec.hs view
@@ -4,6 +4,12 @@ module Configuration.DotenvSpec (main, spec) where  import Configuration.Dotenv.Types (Config(..))+import Configuration.Dotenv.Environment+  ( getEnvironment+  , lookupEnv+  , setEnv+  , unsetEnv+  ) import Configuration.Dotenv   ( load   , loadFile@@ -16,7 +22,6 @@ import Test.Hspec  import System.Process (readCreateProcess, shell)-import System.Environment (lookupEnv) import Control.Monad (liftM, void) import Data.Maybe (fromMaybe) import qualified Data.Text as T@@ -29,12 +34,6 @@ import Control.Applicative ((<$)) #endif -#if MIN_VERSION_base(4,7,0)-import System.Environment (getEnvironment, setEnv, unsetEnv)-#else-import System.Environment.Compat (getEnvironment, setEnv, unsetEnv)-#endif- main :: IO () main = hspec spec @@ -173,6 +172,12 @@       me <- init <$> readCreateProcess (shell "whoami") ""       liftM (!! 4) (parseFile "spec/fixtures/.dotenv") `shouldReturn`         ("ME", me)++#if MIN_VERSION_base(4,11,0)+    it "recognizes blank variable" $+      liftM (!! 5) (parseFile "spec/fixtures/.dotenv") `shouldReturn`+        ("BLANK", "")+#endif    describe "onMissingFile" $ after_ clearEnvs $ do     context "when target file is present" $
spec/fixtures/.dotenv view
@@ -3,3 +3,4 @@ ENVIRONMENT="$HOME" PREVIOUS="$DOTENV" ME="$(whoami)"+BLANK=
src/Configuration/Dotenv.hs view
@@ -9,7 +9,6 @@ -- -- This module contains common functions to load and read dotenv files. -{-# LANGUAGE CPP             #-} {-# LANGUAGE RecordWildCards #-}  module Configuration.Dotenv@@ -33,19 +32,13 @@ import Configuration.Dotenv.Scheme import Configuration.Dotenv.Scheme.Types (ValidatorMap, defaultValidatorMap) import Configuration.Dotenv.Types (Config(..), defaultConfig)+import Configuration.Dotenv.Environment (getEnvironment, lookupEnv, setEnv) import Control.Monad.Catch import Control.Monad.IO.Class (MonadIO(..)) import Data.List (union, intersectBy, unionBy) import System.Directory (doesFileExist)-import System.Environment (lookupEnv) import System.IO.Error (isDoesNotExistError) import Text.Megaparsec (parse, errorBundlePretty)--#if MIN_VERSION_base(4,7,0)-import System.Environment (getEnvironment, setEnv)-#else-import System.Environment.Compat (getEnvironment, setEnv)-#endif  -- | Loads the given list of options into the environment. Optionally -- override existing variables with values from Dotenv files.
+ src/Configuration/Dotenv/Environment.hs view
@@ -0,0 +1,33 @@+{-# LANGUAGE CPP #-}++module Configuration.Dotenv.Environment+  ( getEnvironment+  , lookupEnv+  , setEnv+  , unsetEnv+  ) where++#if MIN_VERSION_base(4,11,0)+import System.Environment.Blank (getEnvironment, unsetEnv)+import qualified System.Environment.Blank as Blank+#else+#if MIN_VERSION_base(4,7,0)+import System.Environment (getEnvironment, setEnv, unsetEnv)+#else+import System.Environment.Compat (getEnvironment, setEnv, unsetEnv)+#endif+#endif++#if MIN_VERSION_base(4,11,0)+import System.Environment.Blank (getEnv)+#else+import System.Environment (lookupEnv)+#endif++#if MIN_VERSION_base(4,11,0)+lookupEnv :: String -> IO (Maybe String)+lookupEnv = getEnv++setEnv :: String -> String -> IO ()+setEnv name value = Blank.setEnv name value True+#endif
src/Configuration/Dotenv/ParsedVariable.hs view
@@ -19,11 +19,11 @@                                             interpolateParsedVariables) where  import Control.Monad (foldM)+import Configuration.Dotenv.Environment (lookupEnv) #if !MIN_VERSION_base(4,8,0) import Data.Functor ((<$>)) #endif import Control.Applicative ((<|>))-import System.Environment (lookupEnv) import System.Process (readCreateProcess, shell)  data ParsedVariable