Skip to content

Commit 8e55100

Browse files
[Deprecate functionality] Remove loadSafeFile (#136)
* Remove references to loadSafeFile * Update version in cabal file * Update README * Update changelog
1 parent 869ebec commit 8e55100

File tree

14 files changed

+30
-602
lines changed

14 files changed

+30
-602
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## MASTER
22

3+
## Dotenv 0.9.0.0
4+
* Remove `loadSafeFile`. Users must create their own parsers to convert the
5+
read values from `System.Environment` to another data type. Therefore,
6+
`loadSafeFile` won't be needed. We'll remove this functionality to reduce
7+
dependencies.
8+
39
## Dotenv 0.8.1.0
410
* Correct bounds for base. GHC support for versions older than 8.0 was dropped.
511

README.md

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -80,46 +80,6 @@ $ dotenv "echo $DATABASE"
8080
postgres://myusername@localhost/database
8181
```
8282

83-
### Type checking envs
84-
Env variables are simple strings. However, they can represent other types like
85-
integers, booleans, IP addresses, emails, URIs, and so on. We provide an interface
86-
that performs type checking after loading the envs and before running your application.
87-
If the type-check succeeded the application is executed, otherwise you will get an
88-
error with the types that mismatch.
89-
90-
In order to use this functionality you can use the `loadSafeFile` which takes the same
91-
configuration value as the `loadFile` function. Also, you need to have a `.schema.yml`
92-
in your current directory. This file must have the following structure:
93-
94-
```yaml
95-
- name: DOTENV
96-
type: bool
97-
required: true
98-
- name: OTHERENV
99-
type: bool
100-
- name: PORT
101-
type: integer
102-
required: true
103-
- name: TOKEN
104-
type: text
105-
required: false
106-
```
107-
108-
It is a list of type and envs. So, in this example, `DOTENV` must have a value
109-
of `true` or `false` otherwise it won't be parsed as a boolean value. And envs
110-
like `PORT` must be any integer. Currently, we are supporting the following types:
111-
112-
- `bool` - Accepts values `false` or `true`
113-
- `integer` - Accepts values of possitive integers
114-
- `text` - Any text
115-
116-
**require** specifies if the env var is obligatory or not. In case you set it to true
117-
but do not provide it, you wil get an exception. When **required** is omited, the default
118-
value is `false`.
119-
120-
**NOTE:** All the variables which are **required** in the `schema.yml` must be defined
121-
in the dotenvs.
122-
12383
## Configuration
12484

12585
The first argument to `loadFile` specifies the configuration. You cans use

app/Main.hs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,27 @@
33

44
module Main where
55

6-
import Data.Version (showVersion)
6+
import Data.Version (showVersion)
77
#if !MIN_VERSION_base(4,13,0)
8-
import Data.Monoid ((<>))
8+
import Data.Monoid ((<>))
99
#endif
1010

11-
import Options.Applicative
12-
import Paths_dotenv (version)
11+
import Options.Applicative
12+
import Paths_dotenv (version)
1313

14-
import Control.Monad (void, unless)
14+
import Control.Monad (void)
1515

16-
import Configuration.Dotenv
17-
(Config(..)
18-
, loadFile
19-
, loadSafeFile
20-
, defaultConfig
21-
, defaultValidatorMap)
16+
import Configuration.Dotenv (Config (..), defaultConfig, loadFile)
2217

23-
import System.Process (system)
24-
import System.Exit (exitWith)
18+
import System.Exit (exitWith)
19+
import System.Process (system)
2520

2621
data Options = Options
2722
{ dotenvFiles :: [String]
2823
, dotenvExampleFiles :: [String]
2924
, override :: Bool
3025
, program :: String
3126
, args :: [String]
32-
, schemaFile :: FilePath
33-
, disableSchema :: Bool
3427
} deriving (Show)
3528

3629
main :: IO ()
@@ -47,8 +40,6 @@ main = do
4740
}
4841
in do
4942
void $ loadFile configDotenv
50-
unless disableSchema
51-
(void $ loadSafeFile defaultValidatorMap schemaFile configDotenv)
5243
system (program ++ concatMap (" " ++) args) >>= exitWith
5344
where
5445
opts = info (helper <*> versionOption <*> config)
@@ -80,10 +71,3 @@ config = Options
8071
<*> argument str (metavar "PROGRAM")
8172

8273
<*> many (argument str (metavar "ARG"))
83-
84-
<*> strOption ( long "schema"
85-
<> short 's'
86-
<> help "Set the file path for the schema.yml file"
87-
<> value ".schema.yml" )
88-
89-
<*> switch ( long "no-schema" <> help "Omit type checking" )

dotenv.cabal

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: dotenv
2-
version: 0.8.1.0
2+
version: 0.9.0.0
33
synopsis: Loads environment variables from dotenv files
44
homepage: https://github.com/stackbuilders/dotenv-hs
55
description:
@@ -49,8 +49,6 @@ data-dir: spec/fixtures/
4949
data-files:
5050
.dotenv
5151
.dotenv.example
52-
.scheme.yml
53-
.dotenv.safe
5452

5553
flag static
5654
description: Creates static binary.
@@ -72,7 +70,6 @@ executable dotenv
7270
, process
7371
, text
7472
, transformers >= 0.4 && < 0.6
75-
, yaml >= 0.8
7673
other-modules: Paths_dotenv
7774

7875
hs-source-dirs: app
@@ -92,10 +89,6 @@ library
9289
, Configuration.Dotenv.ParsedVariable
9390
, Configuration.Dotenv.Text
9491
, Configuration.Dotenv.Types
95-
, Configuration.Dotenv.Scheme
96-
, Configuration.Dotenv.Scheme.Helpers
97-
, Configuration.Dotenv.Scheme.Parser
98-
, Configuration.Dotenv.Scheme.Types
9992

10093
build-depends: base >= 4.9 && < 5.0
10194
, base-compat >= 0.4
@@ -106,7 +99,6 @@ library
10699
, text
107100
, transformers >=0.4 && < 0.6
108101
, exceptions >= 0.8 && < 0.11
109-
, yaml >= 0.8
110102

111103
hs-source-dirs: src
112104
ghc-options: -Wall
@@ -129,12 +121,6 @@ test-suite dotenv-test
129121
, Configuration.Dotenv.Types
130122
, Configuration.Dotenv.Parse
131123
, Configuration.Dotenv.ParsedVariable
132-
, Configuration.Dotenv.SchemeSpec
133-
, Configuration.Dotenv.Scheme.ParseSpec
134-
, Configuration.Dotenv.Scheme
135-
, Configuration.Dotenv.Scheme.Helpers
136-
, Configuration.Dotenv.Scheme.Parser
137-
, Configuration.Dotenv.Scheme.Types
138124

139125
build-depends: base >= 4.9 && < 5.0
140126
, base-compat >= 0.4
@@ -148,8 +134,7 @@ test-suite dotenv-test
148134
, transformers >= 0.4 && < 0.6
149135
, exceptions >= 0.8 && < 0.11
150136
, hspec-megaparsec >= 2.0 && < 3.0
151-
, yaml >= 0.8
152-
137+
153138
build-tools: hspec-discover >= 2.0 && < 3.0
154139

155140
if flag(dev)

spec/Configuration/Dotenv/Scheme/ParseSpec.hs

Lines changed: 0 additions & 35 deletions
This file was deleted.

spec/Configuration/Dotenv/SchemeSpec.hs

Lines changed: 0 additions & 84 deletions
This file was deleted.

spec/Configuration/DotenvSpec.hs

Lines changed: 13 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
1-
{-# LANGUAGE CPP #-}
1+
{-# LANGUAGE CPP #-}
22
{-# LANGUAGE OverloadedStrings #-}
33

44
module Configuration.DotenvSpec (main, spec) where
55

6-
import Configuration.Dotenv.Types (Config(..))
7-
import Configuration.Dotenv.Environment
8-
( getEnvironment
9-
, lookupEnv
10-
, setEnv
11-
, unsetEnv
12-
)
13-
import Configuration.Dotenv
14-
( load
15-
, loadFile
16-
, loadSafeFile
17-
, parseFile
18-
, onMissingFile
19-
)
20-
21-
22-
import Test.Hspec
23-
24-
import System.Process (readCreateProcess, shell)
25-
import Control.Monad (liftM, void)
26-
import Data.Maybe (fromMaybe)
27-
import qualified Data.Text as T
28-
import qualified Data.Map.Lazy as M
6+
import Configuration.Dotenv (load, loadFile,
7+
onMissingFile, parseFile)
8+
import Configuration.Dotenv.Environment (getEnvironment, lookupEnv,
9+
setEnv, unsetEnv)
10+
import Configuration.Dotenv.Types (Config (..))
11+
12+
13+
import Test.Hspec
14+
15+
import Control.Monad (liftM, void)
16+
import Data.Maybe (fromMaybe)
17+
import System.Process (readCreateProcess, shell)
2918

3019
main :: IO ()
3120
main = hspec spec
@@ -100,45 +89,6 @@ spec = do
10089
lookupEnv "UNICODE_TEST" `shouldReturn` Just "Manabí"
10190
lookupEnv "ANOTHER_ENV" `shouldReturn` Just "hello"
10291

103-
describe "loadSafeFile" $ after_ clearEnvs $
104-
context "given a custom map" $ do
105-
context "when the envs are written accordingly to the rules in the map" $
106-
it "should validate accordingly to the rules in the custom map" $
107-
let hasTwoLetters text = T.length text == 2
108-
customMap = M.fromList
109-
[ ("twoLetters", hasTwoLetters)
110-
, ("bool", const True)
111-
, ("text", const True)
112-
, ("integer", const True)
113-
]
114-
schemaFile = "spec/fixtures/.scheme.yml"
115-
config = Config ["spec/fixtures/.dotenv.safe"] [] False
116-
expectedEnvs =
117-
[ ("DOTENV","true")
118-
, ("OTHERENV","false")
119-
, ("PORT","8000")
120-
, ("URL","http://example.com")
121-
, ("TWO","xD")
122-
]
123-
in do
124-
envs <- loadSafeFile customMap schemaFile config
125-
envs `shouldMatchList` expectedEnvs
126-
127-
context "when the envs are written in an unexpected way" $
128-
it "should throw an errorCall" $
129-
let unexpectedFormat text = T.length text == 3
130-
customMap = M.fromList
131-
[ ("twoLetters", unexpectedFormat)
132-
, ("bool", const True)
133-
, ("text", const True)
134-
, ("integer", const True)
135-
]
136-
schemaFile = "spec/fixtures/.scheme.yml"
137-
config = Config ["spec/fixtures/.dotenv.safe"] [] False
138-
in void $ loadSafeFile customMap schemaFile config
139-
`shouldThrow` anyErrorCall
140-
141-
14292
describe "parseFile" $ after_ clearEnvs $ do
14393
it "returns variables from a file without changing the environment" $ do
14494
lookupEnv "DOTENV" `shouldReturn` Nothing

0 commit comments

Comments
 (0)