packages feed

dotenv 0.3.0.1 → 0.3.0.2

raw patch · 5 files changed

+139/−55 lines, 5 filesdep +dotenvdep ~megaparsecnew-uploaderPVP ok

version bump matches the API change (PVP)

Dependencies added: dotenv

Dependency ranges changed: megaparsec

API changes (from Hackage documentation)

Files

+ README.md view
@@ -0,0 +1,87 @@+[![Build Status](https://travis-ci.org/stackbuilders/dotenv-hs.svg?branch=master)](https://travis-ci.org/stackbuilders/dotenv-hs) [![Hackage](https://img.shields.io/hackage/v/dotenv.svg)](http://hackage.haskell.org/package/dotenv)++# Dotenv files for Haskell++In most applications,+[configuration should be separated from code](http://12factor.net/config). While+it usually works well to keep configuration in the environment, there+are cases where you may want to store configuration in a file outside+of version control.++"Dotenv" files have become popular for storing configuration,+especially in development and test environments. In+[Ruby](https://github.com/bkeepers/dotenv),+[Python](https://github.com/theskumar/python-dotenv) and+[Javascript](https://www.npmjs.com/package/dotenv) there are libraries+to facilitate loading of configuration options from configuration+files. This library loads configuration to environment variables for+programs written in Haskell.++## Installation++In most cases you will just add `dotenv` to your cabal file. You can+also install the library and executable by invoking `cabal install dotenv`.++## Usage++Set configuration variables in a file following the format below:++```+S3_BUCKET=YOURS3BUCKET+SECRET_KEY=YOURSECRETKEYGOESHERE+```++Then, calling `Dotenv.load` from your Haskell program reads the above+settings into the environment:++```haskell+import qualified Configuration.Dotenv as Dotenv+Dotenv.loadFile False "/path/to/your/file"+```++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`.++## Configuration++The first argument to `loadFile` specifies whether you want to+override system settings. `False` means Dotenv will respect+already-defined variables, and `True` means Dotenv will overwrite+already-defined variables.++## Advanced Dotenv File Syntax++You can add comments to your Dotenv file, on separate lines or after+values. Values can be wrapped in single or double quotes. Multi-line+values can be specified by wrapping the value in double-quotes, and+using the "\n" character to represent newlines.++The [spec file](spec/Configuration/Dotenv/ParseSpec.hs) is the best+place to understand the nuances of Dotenv file parsing.++## Command-Line Usage++You can call dotenv from the command line in order to load settings+from one or more dotenv file before invoking an executable:++```+dotenv -f mydotenvfile myprogram+```++Hint: The `env` program in most Unix-like environments prints out the+current environment settings. By invoking the program `env` in place+of `myprogram` above you can see what the environment will look like+after evaluating multiple  Dotenv files.++## Author++Justin Leitgeb++## License++MIT++## Copyright++(C) 2015-2016 [Stack Builders Inc.](http://www.stackbuilders.com)
+ app/Main.hs view
@@ -0,0 +1,42 @@+module Main where++import Options.Applicative++import Configuration.Dotenv (loadFile)++import System.Process (system)+import System.Exit (exitWith)++data Options = Options+  { files    :: [String]+  , program  :: String+  , overload :: Bool+  } deriving (Show)++main :: IO ()+main = execParser opts >>= dotEnv+  where+    opts = info (helper <*> config)+      ( fullDesc+     <> progDesc "Runs PROGRAM after loading options from FILE"+     <> header "dotenv - loads options from dotenv files" )++config :: Parser Options+config = Options+     <$> some (strOption (+                  long "file"+                  <> short 'f'+                  <> metavar "FILE"+                  <> help "File to read for options" ))++     <*> argument str (metavar "PROGRAM")++     <*> switch ( long "overload"+                  <> short 'o'+                  <> help "Specify this flag to override existing variables" )++dotEnv :: Options -> IO ()+dotEnv opts = do+  mapM_ (loadFile (overload opts)) (files opts)+  code <- system $ program opts+  exitWith code
dotenv.cabal view
@@ -1,5 +1,5 @@ name:                dotenv-version:             0.3.0.1+version:             0.3.0.2 synopsis:            Loads environment variables from dotenv files homepage:            https://github.com/stackbuilders/dotenv-hs description:@@ -40,24 +40,21 @@ build-type:          Simple extra-source-files:    spec/fixtures/.dotenv                      , CHANGELOG.md+                     , README.md cabal-version:       >=1.10 bug-reports:         https://github.com/stackbuilders/dotenv-hs/issues  executable dotenv   main-is:             Main.hs-  other-modules:       Configuration.Dotenv-                       Configuration.Dotenv.Parse-                     , Configuration.Dotenv.Text--  -- other-extensions:   build-depends:         base >=4.5 && <5.0                        , base-compat >= 0.4+                       , dotenv >= 0.3.0.2                        , optparse-applicative >=0.11 && < 0.13-                       , megaparsec >= 4.2.0 && < 4.5.0+                       , megaparsec >= 5.0 && < 6.0                        , process                        , text -  hs-source-dirs:      src+  hs-source-dirs:      app   default-language:    Haskell2010  library@@ -67,14 +64,13 @@    build-depends:         base >=4.5 && <5.0                        , base-compat >= 0.4-                       , megaparsec >= 4.2.0 && < 4.5.0+                       , megaparsec >= 5.0 && < 6.0                        , text    hs-source-dirs:      src   default-language:    Haskell2010   ghc-options:         -Wall - test-suite dotenv-test   type: exitcode-stdio-1.0   hs-source-dirs: spec, src@@ -88,7 +84,8 @@    build-depends:       base >=4.5 && <5.0                      , base-compat >= 0.4-                     , megaparsec >= 4.2.0 && < 4.5.0+                     , dotenv >= 0.3.0.2+                     , megaparsec >= 5.0 && < 6.0                      , hspec                      , text 
spec/Configuration/Dotenv/ParseSpec.hs view
@@ -6,7 +6,7 @@  import Test.Hspec (it, describe, shouldBe, Spec, hspec) -import Text.Megaparsec (ParseError, parse)+import Text.Megaparsec (ParseError, Dec, parse)  main :: IO () main = hspec spec@@ -90,5 +90,5 @@ isLeft ( Left _ ) = True isLeft _          = False -parseConfig :: String -> Either ParseError [(String, String)]+parseConfig :: String -> Either (ParseError Char Dec) [(String, String)] parseConfig = parse configParser "(unknown)"
− src/Main.hs
@@ -1,42 +0,0 @@-module Main where--import Options.Applicative--import Configuration.Dotenv (loadFile)--import System.Process (system)-import System.Exit (exitWith)--data Options = Options-  { files    :: [String]-  , program  :: String-  , overload :: Bool-  } deriving (Show)--main :: IO ()-main = execParser opts >>= dotEnv-  where-    opts = info (helper <*> config)-      ( fullDesc-     <> progDesc "Runs PROGRAM after loading options from FILE"-     <> header "dotenv - loads options from dotenv files" )--config :: Parser Options-config = Options-     <$> some (strOption (-                  long "file"-                  <> short 'f'-                  <> metavar "FILE"-                  <> help "File to read for options" ))--     <*> argument str (metavar "PROGRAM")--     <*> switch ( long "overload"-                  <> short 'o'-                  <> help "Specify this flag to override existing variables" )--dotEnv :: Options -> IO ()-dotEnv opts = do-  mapM_ (loadFile (overload opts)) (files opts)-  code <- system $ program opts-  exitWith code