packages feed

load-env 0.0.5 → 0.1.0

raw patch · 3 files changed

+30/−36 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

load-env.cabal view
@@ -1,5 +1,5 @@ Name:                   load-env-Version:                0.0.5+Version:                0.1.0 Author:                 Pat Brisbin <pbrisbin@gmail.com> Maintainer:             Pat Brisbin <pbrisbin@gmail.com> License:                BSD3
src/LoadEnv.hs view
@@ -22,11 +22,11 @@ -- > FOO='bar' -- -- Declarations may optionally be preceded by @export@, which will be ignored.--- Lines beginning with @#@ and blank lines are ignored. Trailing whitespace is--- ignored. Quotes inside quoted values or spaces in unquoted values must be--- escaped with a backlash. All else will result in a parse error being printed--- to @stdout@.+-- Trailing whitespace is ignored. Quotes inside quoted values or spaces in+-- unquoted values must be escaped with a backlash. --+-- Invalid lines are silently ignored.+-- -- If you wish to specify your own file, use @'loadEnvFrom'@. If you wish to -- pass your own string or work with the parse result directly, use the -- lower-level functions available in @"LoadEnv.Parse"@.@@ -38,5 +38,5 @@ loadEnvFrom fp = do     e <- doesFileExist fp -    when e $ parseFromFile parseEnvironment fp >>= either-        (putStrLn . show) (mapM_ $ uncurry setEnv)+    when e $ parseFromFile parseEnvironment fp >>=+        either print (mapM_ $ uncurry setEnv)
src/LoadEnv/Parse.hs view
@@ -5,7 +5,8 @@     , parseVariable     ) where -import Control.Applicative ((<$>), (<*>))+import Control.Applicative ((<$>))+import Control.Monad (void) import Data.Maybe (catMaybes)  import Text.Parsec@@ -15,45 +16,38 @@ type Variable = (String, String)  parseEnvironment :: Parser Environment-parseEnvironment = fmap catMaybes $ many1 parseLine+parseEnvironment = catMaybes <$> many parseLine  parseLine :: Parser (Maybe Variable)-parseLine = try (fmap Just $ parseVariable) <|> ignoreLine--ignoreLine :: Parser (Maybe Variable)-ignoreLine = (commentLine <|> blankLine) >> return Nothing--commentLine :: Parser ()-commentLine = do-    _ <- spaces-    _ <- char '#'-    _ <- manyTill anyToken (char '\n')+parseLine = possibly parseVariable -    return ()+possibly :: Parser a -> Parser (Maybe a)+possibly p = try (fmap Just p) <|> ignored -blankLine :: Parser ()-blankLine = many1 space >> return ()+  where+    ignored = do+        void $ manyTill anyToken newline+        return Nothing  parseVariable :: Parser Variable-parseVariable = (,) <$> identifier <*> value--identifier :: Parser String-identifier = do+parseVariable = do     optional $ between spaces spaces $ string "export" -    i <- many1 $ letter <|> char '_'-    _ <- char '='+    i <- identifier+    void $ char '=' -    return i+    v <- value+    void $ many $ oneOf " \t"+    void $ newline -value :: Parser String-value = do-    v <- quotedValue <|> unquotedValue <|> return ""-    _ <- many $ oneOf " \t"-    _ <- char '\n'+    return (i, v) -    return v+identifier :: Parser String+identifier = many1 $ letter <|> char '_' +value :: Parser String+value = quotedValue <|> unquotedValue <|> return ""+ quotedValue :: Parser String quotedValue = do     q <- oneOf "'\""@@ -61,7 +55,7 @@     manyTill (try (escaped q) <|> anyToken) (char q)  unquotedValue :: Parser String-unquotedValue = many1 $ try (escaped ' ') <|> (noneOf "\"' \n")+unquotedValue = many1 $ try (escaped ' ') <|> noneOf "\"' \n"  escaped :: Char -> Parser Char escaped c = string ("\\" ++ [c]) >> return c