Skip to content

Commit fad5561

Browse files
misc: Updates some documentation and refactors a little bit (#154)
* doc: Update cabal Intro * doc: Update cabal Intro * ref: Move helpers to new module * chore: Replace custom instance with library type * fix: Include mtl in tests * bump version 0.10.0.1
1 parent 60cb25f commit fad5561

File tree

5 files changed

+21
-41
lines changed

5 files changed

+21
-41
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
## MASTER
2+
## Dotenv 0.10.0.1
3+
### Modified
4+
* Modify docs.
5+
26
## Dotenv 0.10.0.0
37
### Modified
48
* `loadFile` change return type (back to `m ()`)

dotenv.cabal

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
name: dotenv
2-
version: 0.10.0.0
2+
version: 0.10.0.1
33
synopsis: Loads environment variables from dotenv files
44
homepage: https://github.com/stackbuilders/dotenv-hs
55
description:
66
.
77
In most applications,
8-
<http://12factor.net/config configuration should be separated from code>.
8+
<https://12factor.net/config configuration should be separated from code>.
99
While it usually works well to keep configuration in the
1010
environment, there are cases where you may want to store
1111
configuration in a file outside of version control.
1212
.
13-
"Dotenv" files have become popular for storing configuration,
13+
@Dotenv@ files have become popular for storing configuration,
1414
especially in development and test environments. In
1515
<https://github.com/bkeepers/dotenv Ruby>,
1616
<https://github.com/theskumar/python-dotenv Python> and
17-
<https://www.npmjs.com/package/dotenv Javascript> there are libraries
17+
<https://www.npmjs.com/package/dotenv JavaScript> there are libraries
1818
to facilitate loading of configuration options from configuration
1919
files. This library loads configuration to environment variables for
2020
programs written in Haskell.
2121
.
2222
To use, call `loadFile` from your application:
2323
.
24-
> import Control.Monad (void)
2524
> import Configuration.Dotenv
26-
> void $ loadFile defaultConfig
25+
> loadFile defaultConfig
2726
.
2827
This package also includes an executable that can be used
2928
to inspect the results of applying one or more Dotenv files
3029
to the environment, or for invoking your executables with
3130
an environment after one or more Dotenv files is applied.
3231
.
33-
See the <https://github.com/stackbuilders/dotenv-hs Github>
32+
See the <https://github.com/stackbuilders/dotenv-hs#readme Github>
3433
page for more information on this package.
3534
license: MIT
3635
license-file: LICENSE
3736
author: Justin Leitgeb
3837
maintainer: hackage@stackbuilders.com
39-
copyright: 2015-2020 Stack Builders Inc.
38+
copyright: 2015-Present Stack Builders Inc.
4039
category: Configuration
4140
build-type: Simple
4241
extra-source-files: spec/fixtures/.dotenv
@@ -97,6 +96,7 @@ library
9796
, shellwords >= 0.1.3.0
9897
, text
9998
, exceptions >= 0.8 && < 0.11
99+
, mtl >= 2.3 && < 2.4
100100

101101
hs-source-dirs: src
102102
ghc-options: -Wall
@@ -132,6 +132,7 @@ test-suite dotenv-test
132132
, text
133133
, exceptions >= 0.8 && < 0.11
134134
, hspec-megaparsec >= 2.0 && < 3.0
135+
, mtl
135136

136137
build-tools: hspec-discover >= 2.0 && < 3.0
137138

src/Configuration/Dotenv.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import Configuration.Dotenv.Environment (getEnvironment, lookupEnv,
2424
setEnv)
2525
import Configuration.Dotenv.Parse (configParser)
2626
import Configuration.Dotenv.ParsedVariable (interpolateParsedVariables)
27-
import Configuration.Dotenv.Types (Config (..), ReaderT, ask,
28-
defaultConfig,
29-
liftReaderT, runReaderT)
27+
import Configuration.Dotenv.Types (Config (..), defaultConfig)
28+
import Control.Monad.Trans (lift)
29+
import Control.Monad.Reader (ReaderT, ask, runReaderT)
3030
import Control.Exception (throw)
3131
import Control.Monad (unless, when)
3232
import Control.Monad.Catch
@@ -97,20 +97,20 @@ applySetting kv@(k, v) = do
9797
if configOverride
9898
then info kv >> setEnv'
9999
else do
100-
res <- liftReaderT . liftIO $ lookupEnv k
100+
res <- lift . liftIO $ lookupEnv k
101101
case res of
102102
Nothing -> info kv >> setEnv'
103103
Just _ -> return kv
104104
where
105-
setEnv' = liftReaderT . liftIO $ setEnv k v >> return kv
105+
setEnv' = lift . liftIO $ setEnv k v >> return kv
106106

107107
-- | The function logs in console when a variable is loaded into the
108108
-- environment.
109109
info :: MonadIO m => (String, String) -> DotEnv m ()
110110
info (key, value) = do
111111
Config {..} <- ask
112112
when configVerbose $
113-
liftReaderT . liftIO $
113+
lift . liftIO $
114114
putStrLn $ "[INFO]: Load env '" ++ key ++ "' with value '" ++ value ++ "'"
115115

116116
-- | The helper allows to avoid exceptions in the case of missing files and

src/Configuration/Dotenv/Environment.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import System.Environment (getEnvironment, lookupEnv, setEnv, unsetEnv)
1515
#endif
1616

1717
#if MIN_VERSION_base(4,11,0)
18+
-- | Re-export "System.Environment" or "System.Environment.Blank" helpers.
1819
lookupEnv :: String -> IO (Maybe String)
1920
lookupEnv = getEnv
2021

22+
-- | Re-export "System.Environment" or "System.Environment.Blank" helpers.
2123
setEnv :: String -> String -> IO ()
2224
setEnv name value = Blank.setEnv name value True
2325
#endif

src/Configuration/Dotenv/Types.hs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
module Configuration.Dotenv.Types
1313
( Config(..)
1414
, defaultConfig
15-
, ask
16-
, runReaderT
17-
, liftReaderT
18-
, ReaderT
1915
)
2016
where
2117

@@ -39,26 +35,3 @@ defaultConfig =
3935
, configVerbose = False
4036
, allowDuplicates = True
4137
}
42-
43-
44-
newtype ReaderT r m a = ReaderT { runReaderT :: r -> m a }
45-
mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b
46-
mapReaderT f m = ReaderT $ f . runReaderT m
47-
instance (Functor m) => Functor (ReaderT r m) where
48-
fmap f = mapReaderT (fmap f)
49-
instance (Applicative m) => Applicative (ReaderT r m) where
50-
pure = liftReaderT . pure
51-
f <*> v = ReaderT $ \ r -> runReaderT f r <*> runReaderT v r
52-
53-
instance (Monad m) => Monad (ReaderT r m) where
54-
return = liftReaderT . return
55-
m >>= k = ReaderT $ \ r -> do
56-
a <- runReaderT m r
57-
runReaderT (k a) r
58-
m >> k = ReaderT $ \ r -> runReaderT m r >> runReaderT k r
59-
60-
liftReaderT :: m a -> ReaderT r m a
61-
liftReaderT m = ReaderT (const m)
62-
63-
ask :: (Monad m) => ReaderT r m r
64-
ask = ReaderT return

0 commit comments

Comments
 (0)