dotenv 0.1.0.1 → 0.1.0.2
raw patch · 3 files changed
+23/−32 lines, 3 filesdep +base-compatdep ~basePVP ok
version bump matches the API change (PVP)
Dependencies added: base-compat
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- dotenv.cabal +7/−4
- src/Configuration/Dotenv.hs +1/−1
- src/Configuration/Dotenv/Parse.hs +15/−27
dotenv.cabal view
@@ -1,5 +1,5 @@ name: dotenv-version: 0.1.0.1+version: 0.1.0.2 synopsis: Loads environment variables from dotenv files description:@@ -45,7 +45,8 @@ main-is: Main.hs -- other-modules: -- other-extensions:- build-depends: base >=4.7 && <4.8+ build-depends: base >=4.5 && <4.8+ , base-compat >= 0.4 , optparse-applicative >=0.11 && <0.12 , parsec >= 3.1.0 && <= 3.2 , process@@ -57,7 +58,8 @@ exposed-modules: Configuration.Dotenv.Parse , Configuration.Dotenv - build-depends: base >=4.7 && <4.8+ build-depends: base >=4.5 && <4.8+ , base-compat >= 0.4 , parsec >= 3.1.0 && <= 3.2 hs-source-dirs: src@@ -69,7 +71,8 @@ type: exitcode-stdio-1.0 hs-source-dirs: spec, src main-is: Spec.hs- build-depends: base >=4.7 && <4.8+ build-depends: base >=4.5 && <4.8+ , base-compat >= 0.4 , parsec >= 3.1.0 && <= 3.2 , hspec
src/Configuration/Dotenv.hs view
@@ -1,6 +1,6 @@ module Configuration.Dotenv (load, loadFile) where -import System.Environment (lookupEnv, setEnv)+import System.Environment.Compat (lookupEnv, setEnv) import Configuration.Dotenv.Parse (configParser)
src/Configuration/Dotenv/Parse.hs view
@@ -1,22 +1,16 @@ module Configuration.Dotenv.Parse (configParser) where import Data.Maybe (catMaybes)--import Text.Parsec- ((<|>), many, try, lookAhead, manyTill, char, anyChar, many1)- import Text.Parsec.String (Parser)- import Text.ParserCombinators.Parsec.Prim (GenParser)- import Text.ParserCombinators.Parsec.Char (space, newline, oneOf, noneOf)- import Control.Monad (liftM2)- import Text.Parsec.Combinator (eof)- import Control.Applicative ((<*), (*>), (<$>))+import Text.Parsec+ ((<|>), many, try, lookAhead, manyTill, char, anyChar, many1) + -- | Returns a parser for a Dotenv configuration file. -- Accepts key and value arguments separated by "=". -- Comments are allowed on lines by themselves and on@@ -24,6 +18,7 @@ configParser :: Parser [(String, String)] configParser = catMaybes <$> many lineWithArguments + lineWithArguments :: Parser (Maybe (String, String)) lineWithArguments = comment *> return Nothing@@ -32,25 +27,19 @@ <|> Just <$> configurationOptionWithArguments configurationOptionWithArguments :: Parser (String, String)-configurationOptionWithArguments = do- _ <- many space-- keyword <- manyTill1 (noneOf "\n ") keywordArgSeparator-- arguments <- argumentParser-- return (keyword, arguments)+configurationOptionWithArguments = liftM2 (,)+ (many space *> manyTill1 (noneOf "\n ") keywordArgSeparator)+ argumentParser argumentParser :: Parser String-argumentParser = try quotedArgument <|> try unquotedArgument+argumentParser = quotedArgument <|> unquotedArgument -- | Based on a commented-string parser in: -- http://hub.darcs.net/navilan/XMonadTasks/raw/Data/Config/Lexer.hs quotedWith :: Char -> Parser String quotedWith c =- char c- *> many chr- <* char c+ char c *> many chr <* char c+ where chr = esc <|> noneOf [c] esc = escape *> char c @@ -59,14 +48,13 @@ unquotedArgument :: Parser String unquotedArgument =- many (noneOf " \t\n#") <* (try comment <|> try verticalSpace *> return () <|>- lookAhead (try endOfLineOrInput))+ many (noneOf " \t\n#") <* (comment <|> try verticalSpace *> return ()+ <|> lookAhead (try endOfLineOrInput)) comment :: Parser ()-comment =- try (many verticalSpace *> char '#')- *> manyTill anyChar endOfLineOrInput- *> return ()+comment = try (many verticalSpace *> char '#')+ *> manyTill anyChar endOfLineOrInput+ *> return () endOfLineOrInput :: Parser () endOfLineOrInput = newline *> return () <|> eof