diff --git a/.travis.yml b/.travis.yml index 149f901..9f62cf8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,33 @@ -language: haskell +env: + - CABALVER=1.18 GHCVER=7.8.4 + - CABALVER=1.22 GHCVER=7.10.1 + - CABALVER=head GHCVER=head -ghc: 7.8.2 +matrix: + allow_failures: + - env: CABALVER=head GHCVER=head -notifications: - email: false +install: + - travis_retry sudo add-apt-repository -y ppa:hvr/ghc + - travis_retry sudo apt-get update + - travis_retry sudo apt-get install cabal-install-$CABALVER ghc-$GHCVER + - export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH + - cabal --version + - echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]" + - travis_retry cabal update + - cabal install --only-dependencies --enable-tests --enable-benchmarks + +script: + - cabal configure --enable-tests --enable-benchmarks -v2 + - cabal build + - cabal test + - cabal check + - cabal sdist + - export SRC_TGZ=$(cabal info . | awk '{print $2 ".tar.gz";exit}') ; + cd dist/; + if [ -f "$SRC_TGZ" ]; then + cabal install --force-reinstalls "$SRC_TGZ"; + else + echo "expected '$SRC_TGZ' not found"; + exit 1; + fi diff --git a/README.md b/README.md index b8b3acb..1b58a1f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # load-env +[![Build Status](https://travis-ci.org/pbrisbin/load-env.svg?branch=master)](https://travis-ci.org/pbrisbin/load-env) + This is effectively a port of [dotenv][], whose README explains it best: > Storing configuration in the environment is one of the tenets of a diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/load-env.cabal b/load-env.cabal index a89efbd..3d5155f 100644 --- a/load-env.cabal +++ b/load-env.cabal @@ -1,41 +1,42 @@ -Name: load-env -Version: 0.1.0 -Author: Pat Brisbin -Maintainer: Pat Brisbin -License: BSD3 -License-File: LICENSE -Synopsis: Load environment variables from a file. -Description: Parse a .env file and load any declared variables into +name: load-env +version: 0.1.1 +author: Pat Brisbin +maintainer: Pat Brisbin +license: BSD3 +license-file: LICENSE +synopsis: Load environment variables from a file. +category: Configuration +description: Parse a .env file and load any declared variables into the current process's environment. This allows for a .env file to specify development-friendly defaults for configuration values normally set in the deployment environment. -Cabal-Version: >= 1.10 -Build-Type: Simple +cabal-version: >= 1.10 +build-type: Simple -Library - Default-Language: Haskell2010 - HS-Source-Dirs: src - GHC-Options: -Wall - Exposed-Modules: LoadEnv +library + default-language: Haskell2010 + hs-source-dirs: src + ghc-options: -Wall + exposed-modules: LoadEnv , LoadEnv.Parse - Build-Depends: base >= 4.7.0 && < 5 + build-depends: base >= 4.7.0 && < 5 , directory , parsec -Test-Suite spec - Type: exitcode-stdio-1.0 - Default-Language: Haskell2010 - Hs-Source-Dirs: test - Ghc-Options: -Wall - Main-Is: Spec.hs - Build-Depends: base +test-suite spec + type: exitcode-stdio-1.0 + default-language: Haskell2010 + hs-source-dirs: test + ghc-options: -Wall + main-is: Spec.hs + build-depends: base , load-env , directory , hspec , HUnit , parsec -Source-Repository head - Type: git - Location: https://github.com/pbrisbin/load-env +source-repository head + type: git + location: https://github.com/pbrisbin/load-env diff --git a/src/LoadEnv/Parse.hs b/src/LoadEnv/Parse.hs index 97472b4..7e015c2 100644 --- a/src/LoadEnv/Parse.hs +++ b/src/LoadEnv/Parse.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} module LoadEnv.Parse ( Environment , Variable @@ -5,7 +6,10 @@ module LoadEnv.Parse , parseVariable ) where +#if __GLASGOW_HASKELL__ < 710 import Control.Applicative ((<$>)) +#endif + import Control.Monad (void) import Data.Maybe (catMaybes) @@ -42,8 +46,22 @@ parseVariable = do return (i, v) +-- Environment variable names used by the utilities in the Shell and Utilities +-- volume of IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, +-- and the '_' (underscore) from the characters defined in Portable Character +-- Set and do not begin with a digit. +-- +-- +-- identifier :: Parser String -identifier = many1 $ letter <|> char '_' +identifier = do + x <- upper <|> underscore + ys <- many $ upper <|> digit <|> underscore + + return (x:ys) + + where + underscore = char '_' value :: Parser String value = quotedValue <|> unquotedValue <|> return "" diff --git a/test/LoadEnv/ParseSpec.hs b/test/LoadEnv/ParseSpec.hs index 8f0dd63..7d89cbe 100644 --- a/test/LoadEnv/ParseSpec.hs +++ b/test/LoadEnv/ParseSpec.hs @@ -78,6 +78,17 @@ spec = do it "discards any lines using `export'" $ "export FOO=bar\n" `shouldParseTo` ("FOO", "bar") + context "valid identifier" $ do + it "consists solely of uppercase letters, digits, and the '_'" $ do + "S3_KEY=abc123\n" `shouldParseTo` ("S3_KEY", "abc123") + "_S3_KEY=abc123\n" `shouldParseTo` ("_S3_KEY", "abc123") + expectFailedParse "S3~KEY=abc123\n" + expectFailedParse "S3-KEY=abc123\n" + expectFailedParse "S3_key=abc123\n" + + it "does not begine with a digit" $ + expectFailedParse "3_KEY=abc123\n" + shouldParseTo :: String -> Variable -> Expectation shouldParseTo input expected = case parse parseVariable "" input of