-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | An environmentally friendly way to deal with environment variables
--   
--   For package use information see the <a>README.md</a>
@package envy
@version 1.5.1.0


-- | <pre>
--   {-# LANGUAGE DeriveGeneric #-}
--   
--   module Main ( main ) where
--   
--   import System.Envy
--   import GHC.Generics
--   
--   data PGConfig = PGConfig {
--     pgHost :: String -- "PG_HOST"
--   , pgPort :: Int    -- "PG_PORT"
--   } deriving (Generic, Show)
--   
--   -- Default instance used if environment variable doesn't exist
--   instance DefConfig PGConfig where
--     defConfig = PGConfig "localhost" 5432
--   
--   instance FromEnv PGConfig
--   -- Generically produces the following body (no implementation needed if using Generics):
--   -- fromEnv = PGConfig &lt;$&gt; envMaybe "PG_HOST" .!= "localhost"
--   --                    &lt;*&gt; envMaybe "PG_PORT" .!= 5432
--   
--   main :: IO ()
--   main =
--     print =&lt;&lt; do decodeEnv :: IO (Either String PGConfig)
--    -- PGConfig { pgHost = "custom-pg-url", pgPort = 5432 }
--   </pre>
module System.Envy

-- | <a>FromEnv</a> Typeclass w/ Generic default implementation
class FromEnv a
fromEnv :: FromEnv a => Parser a
fromEnv :: (FromEnv a, DefConfig a, Generic a, GFromEnv (Rep a)) => Parser a

-- | Type class for objects which can be converted to a set of environment
--   variable settings.
class ToEnv a

-- | Convert an object into a list of environment variable settings.
toEnv :: ToEnv a => a -> EnvList a

-- | Class for converting to / from an environment variable
class Typeable a => Var a

-- | Convert a value into an environment variable.
toVar :: Var a => a -> String

-- | Parse an environment variable.
fromVar :: Var a => String -> Maybe a

-- | List of environment variables. Captures a "phantom type" which allows
--   the type checker to detect the proper implementation of toEnv to use.
data EnvList a

-- | Parser Monad for environment variable retrieval
newtype Parser a
Parser :: ExceptT String IO a -> Parser a
[runParser] :: Parser a -> ExceptT String IO a

-- | Environment retrieval with failure info
decodeEnv :: FromEnv a => IO (Either String a)

-- | Environment retrieval (with no failure info)
decode :: FromEnv a => IO (Maybe a)

-- | Display all environment variables, for convenience
showEnv :: IO ()

-- | Set environment via a ToEnv constrained type
setEnvironment :: EnvList a -> IO (Either String ())

-- | Set environment directly using a value of class ToEnv
setEnvironment' :: ToEnv a => a -> IO (Either String ())

-- | Unset Environment from a <a>ToEnv</a> constrained type
unsetEnvironment :: EnvList a -> IO (Either String ())

-- | Unset Environment using a value of class ToEnv
unsetEnvironment' :: ToEnv a => a -> IO (Either String ())

-- | Smart constructor, environment creation helper.
makeEnv :: [EnvVar] -> EnvList a

-- | Environment variable getter. Fails if the variable is not set or fails
--   to parse.
env :: Var a => String -> Parser a

-- | Environment variable getter returning <a>Maybe</a>
envMaybe :: Var a => String -> Parser (Maybe a)

-- | Infix environment variable setter Smart constructor for producing
--   types of <a>EnvVar</a>
(.=) :: Var a => String -> a -> EnvVar

-- | For use with <a>envMaybe</a> for providing default arguments.
(.!=) :: Parser (Maybe a) -> a -> Parser a

-- | Type class for objects which have a default configuration.
class DefConfig a
defConfig :: DefConfig a => a

-- | For customizing environment variable generation
data Option
Option :: Int -> String -> Option

-- | Applied first
[dropPrefixCount] :: Option -> Int

-- | Converted toUpper
[customPrefix] :: Option -> String

-- | For use with Generics, no <a>FromEnv</a> typeclass necessary
--   
--   <pre>
--   getPgConfig :: IO (Either String ConnectInfo)
--   getPgConfig = runEnv $ gFromEnvCustom defOption
--   </pre>
runEnv :: Parser a -> IO (Either String a)

-- | Meant for specifying a custom <a>Option</a> for environment retrieval
--   
--   <pre>
--   instance FromEnv PGConfig where
--     fromEnv = gFromEnvCustom Option { dropPrefixCount = 8, customPrefix = "PG" }
--   </pre>
gFromEnvCustom :: forall a. (DefConfig a, Generic a, GFromEnv (Rep a)) => Option -> Parser a
instance GHC.Show.Show (System.Envy.EnvList a)
instance GHC.Show.Show System.Envy.Option
instance GHC.Classes.Eq System.Envy.EnvVar
instance GHC.Show.Show System.Envy.EnvVar
instance GHC.Base.MonadPlus System.Envy.Parser
instance GHC.Base.Alternative System.Envy.Parser
instance Control.Monad.IO.Class.MonadIO System.Envy.Parser
instance Control.Monad.Error.Class.MonadError GHC.Base.String System.Envy.Parser
instance GHC.Base.Applicative System.Envy.Parser
instance GHC.Base.Monad System.Envy.Parser
instance GHC.Base.Functor System.Envy.Parser
instance (GHC.Generics.Selector s, System.Envy.Var a) => System.Envy.GFromEnv (GHC.Generics.S1 s (GHC.Generics.K1 i a))
instance System.Envy.Var Data.Text.Internal.Text
instance System.Envy.Var Data.Text.Internal.Lazy.Text
instance System.Envy.Var Data.ByteString.Lazy.Internal.ByteString
instance System.Envy.Var Data.ByteString.Internal.ByteString
instance System.Envy.Var GHC.Types.Int
instance System.Envy.Var GHC.Int.Int8
instance System.Envy.Var GHC.Int.Int16
instance System.Envy.Var GHC.Int.Int32
instance System.Envy.Var GHC.Int.Int64
instance System.Envy.Var GHC.Integer.Type.Integer
instance System.Envy.Var Data.Time.Clock.Internal.UTCTime.UTCTime
instance System.Envy.Var Data.Time.Calendar.Days.Day
instance System.Envy.Var GHC.Word.Word8
instance System.Envy.Var GHC.Types.Bool
instance System.Envy.Var GHC.Types.Double
instance System.Envy.Var GHC.Word.Word16
instance System.Envy.Var GHC.Word.Word32
instance System.Envy.Var GHC.Word.Word64
instance System.Envy.Var GHC.Base.String
instance System.Envy.Var ()
instance System.Envy.Var a => System.Envy.Var (GHC.Maybe.Maybe a)
instance (System.Envy.GFromEnv a, System.Envy.GFromEnv b) => System.Envy.GFromEnv (a GHC.Generics.:*: b)
instance System.Envy.GFromEnv a => System.Envy.GFromEnv (GHC.Generics.C1 i a)
instance System.Envy.GFromEnv a => System.Envy.GFromEnv (GHC.Generics.D1 i a)
