packages feed

envy 1.1.0.0 → 1.2.0.0

raw patch · 3 files changed

+50/−21 lines, 3 filesdep ~basedep ~bytestringdep ~envyPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base, bytestring, envy, mtl, text, time, transformers

API changes (from Hackage documentation)

- System.Envy: instance (GHC.Generics.Selector s, Data.Typeable.Internal.Typeable a, System.Envy.Var a) => System.Envy.GFromEnv (GHC.Generics.S1 s (GHC.Generics.K1 i a))
+ System.Envy: instance (GHC.Generics.Selector s, System.Envy.Var a) => System.Envy.GFromEnv (GHC.Generics.S1 s (GHC.Generics.K1 i a))
- System.Envy: (.!=) :: (Typeable a, Var a) => Parser (Maybe a) -> a -> Parser a
+ System.Envy: (.!=) :: Parser (Maybe a) -> a -> Parser a
- System.Envy: env :: (Typeable a, Var a) => String -> Parser a
+ System.Envy: env :: forall a. (Var a) => String -> Parser a
- System.Envy: envMaybe :: (Typeable a, Var a) => String -> Parser (Maybe a)
+ System.Envy: envMaybe :: forall a. (Var a) => String -> Parser (Maybe a)
- System.Envy: fromEnv :: FromEnv a => Parser a
+ System.Envy: fromEnv :: (FromEnv a, DefConfig a, Generic a, GFromEnv (Rep a)) => Parser a
- System.Envy: gFromEnvCustom :: (DefConfig a, Generic a, GFromEnv (Rep a)) => Option -> Parser a
+ System.Envy: gFromEnvCustom :: forall a. (DefConfig a, Generic a, GFromEnv (Rep a)) => Option -> Parser a
- System.Envy: makeEnv :: ToEnv a => [EnvVar] -> EnvList a
+ System.Envy: makeEnv :: [EnvVar] -> EnvList a
- System.Envy: unsetEnvironment :: ToEnv a => EnvList a -> IO (Either String ())
+ System.Envy: unsetEnvironment :: EnvList a -> IO (Either String ())

Files

README.md view
@@ -63,7 +63,7 @@   - Lookups don't attempt to parse the returned type into something meaningful (everything is returned as a `String`)  What if we could apply aeson's `FromJSON` / `ToJSON` pattern to give us variable lookups that provide both key-lookup and parse failure information?-Armed with the `GeneralizedNewTypeDeriving` extension we can derive instances of `Var` that will parse to and from an environment. The `Var` typeclass is simply:+Armed with the `GeneralizedNewTypeDeriving` extension we can derive instances of `Var` that will parse to and from an environment variable. The `Var` typeclass is simply: ```haskell class Var a where   toVar   :: a -> String@@ -148,14 +148,14 @@ -- This record corresponds to our environment, where the field names become the variable names, and the values the environment variable value data PGConfig = PGConfig {     pgHost :: String -- "PG_HOST"-  , pgHost :: Int    -- "PG_PORT"+  , pgPort :: Int    -- "PG_PORT"   } deriving (Generic, Show)  -- Default configuration will be used for fields that could not be retrieved from the environment instance DefConfig PGConfig where   defConfig = PGConfig "localhost" 5432 -instance FromEnv PGConfig +instance FromEnv PGConfig -- Generically creates instance for retrieving environment variables (PG_HOST, PG_PORT)  main :: IO ()@@ -191,5 +191,35 @@ main :: IO () main =   print =<< decodeEnv :: IO (Either String PGConfig)+ -- PGConfig { pgHost = "customUrl", pgPort = 5432 }+```++It's also possible to avoid typeclasses altogether using `runEnv` with `gFromEnvCustom`.++```haskell+{-# LANGUAGE DeriveGeneric #-}+module Main where++import System.Envy+import GHC.Generics++data PGConfig = PGConfig {+    connectHost :: String -- "PG_HOST"+  , connectPort :: Int    -- "PG_PORT"+  } deriving (Generic, Show)++-- Default PGConfig+instance DefConfig PGConfig where+  defConfig = PGConfig "localhost" 5432++-- All fields will be converted to uppercase+getPGEnv :: IO (Either String PGConfig)+getPGEnv = runEnv $ gFromEnvCustom Option {+                    dropPrefixCount = 7+                  , customPrefix = "PG"+		  }++main :: IO ()+main = print =<< getPGEnv  -- PGConfig { pgHost = "customUrl", pgPort = 5432 } ```
envy.cabal view
@@ -1,5 +1,5 @@ name:                envy-version:             1.1.0.0+version:             1.2.0.0 synopsis:            An environmentally friendly way to deal with environment variables license:             BSD3 license-file:        LICENSE@@ -25,8 +25,8 @@                       , containers   == 0.5.*                       , mtl          == 2.2.*                       , text         == 1.2.*-                      , time         == 1.5.*-                      , transformers == 0.4.*+                      , time         >= 1.5 && < 1.7+                      , transformers >= 0.4 && < 0.6   default-language:     Haskell2010  test-suite spec@@ -34,16 +34,16 @@     ghc-options:        -Wall     hs-source-dirs:     tests     main-is:            Main.hs-    build-depends:      base                 >= 4.7 && < 5-                      , bytestring           == 0.10.*+    build-depends:      base+                      , bytestring                       , envy                 == 1.1.*                       , hspec                == 2.2.*-                      , mtl                  == 2.2.*+                      , mtl                       , quickcheck-instances == 0.3.*                       , QuickCheck           == 2.8.*-                      , text                 == 1.2.*-                      , time                 == 1.5.*-                      , transformers         == 0.4.*+                      , text+                      , time+                      , transformers     default-language:   Haskell2010  
src/System/Envy.hs view
@@ -111,7 +111,7 @@ ------------------------------------------------------------------------------ -- | Environment variable getter getE-  :: forall a . (Typeable a, Var a)+  :: forall a . (Var a)   => String   -> Parser a getE k = do@@ -126,7 +126,7 @@  ------------------------------------------------------------------------------ -- | Environment variable getter-env :: forall a. (Typeable a, Var a)+env :: forall a. (Var a)     => String     -> Parser a env = getE@@ -134,7 +134,7 @@ ------------------------------------------------------------------------------ -- | Environment variable getter returning `Maybe` getEMaybe-  :: forall a . (Typeable a, Var a)+  :: forall a . (Var a)   => String   -> Parser (Maybe a) getEMaybe k = do@@ -145,15 +145,14 @@  ------------------------------------------------------------------------------ -- | Environment variable getter returning `Maybe`-envMaybe :: forall a. (Typeable a, Var a)+envMaybe :: forall a. (Var a)   => String   -> Parser (Maybe a) envMaybe = getEMaybe  ------------------------------------------------------------------------------ -- | For use with (.:?) for providing default arguments-(.!=) :: forall a. (Typeable a, Var a)-  => Parser (Maybe a)+(.!=) :: Parser (Maybe a)   -> a   -> Parser a (.!=) p x  = fmap (fromMaybe x) p@@ -218,7 +217,7 @@  ------------------------------------------------------------------------------ -- | Construct a `Parser` from a `selName` and `DefConfig` record field-instance (Selector s, Typeable a, Var a) => GFromEnv (S1 s (K1 i a)) where+instance (Selector s, Var a) => GFromEnv (S1 s (K1 i a)) where   gFromEnv m@(M1 (K1 def)) opts =       M1 . K1 <$> envMaybe (toEnvName opts $ selName m) .!= def     where@@ -253,7 +252,7 @@  ------------------------------------------------------------------------------ -- | smart constructor, Environment creation helper-makeEnv :: ToEnv a => [EnvVar] -> EnvList a+makeEnv :: [EnvVar] -> EnvList a makeEnv = EnvList  ------------------------------------------------------------------------------@@ -312,7 +311,7 @@  ------------------------------------------------------------------------------ -- | Unset Environment from a `ToEnv` constrained type-unsetEnvironment :: ToEnv a => EnvList a -> IO (Either String ())+unsetEnvironment :: EnvList a -> IO (Either String ()) unsetEnvironment (EnvList xs) = do   result <- try $ mapM_ (unsetEnv . fst . getEnvVar) xs   return $ case result of