module Conferer
(
mkConfig
, mkConfig'
, fetch
, fetch'
, fetchKey
, fetchFromConfig
, safeFetchKey
, unsafeFetchKey
, DefaultConfig(..)
, FromConfig
, Config
, Key
) where
import Data.Text (Text)
import Data.Typeable (Typeable)
import Conferer.Config.Internal
import Conferer.Config.Internal.Types
import Conferer.FromConfig.Internal
import Conferer.Key
import qualified Conferer.Source.Env as Env
import qualified Conferer.Source.CLIArgs as Cli
import qualified Conferer.Source.PropertiesFile as PropertiesFile
import Conferer.Config (Defaults)
fetch :: forall a. (FromConfig a, Typeable a, DefaultConfig a) => Config -> IO a
fetch :: Config -> IO a
fetch Config
c = Config -> a -> IO a
forall a. (Typeable a, FromConfig a) => Config -> a -> IO a
fetchFromRootConfigWithDefault Config
c a
forall a. DefaultConfig a => a
configDef
fetch' :: forall a. (FromConfig a, Typeable a) => Config -> a -> IO a
fetch' :: Config -> a -> IO a
fetch' = Config -> a -> IO a
forall a. (Typeable a, FromConfig a) => Config -> a -> IO a
fetchFromRootConfigWithDefault
fetchKey :: forall a. (FromConfig a, Typeable a) => Config -> Key -> a -> IO a
fetchKey :: Config -> Key -> a -> IO a
fetchKey = Config -> Key -> a -> IO a
forall a. (Typeable a, FromConfig a) => Config -> Key -> a -> IO a
fetchFromConfigWithDefault
safeFetchKey :: forall a. (FromConfig a, Typeable a) => Config -> Key -> IO (Maybe a)
safeFetchKey :: Config -> Key -> IO (Maybe a)
safeFetchKey Config
c Key
k = Key -> Config -> IO (Maybe a)
forall a. (FromConfig a, Typeable a) => Key -> Config -> IO a
fetchFromConfig Key
k Config
c
unsafeFetchKey :: forall a. (FromConfig a, Typeable a) => Config -> Key -> IO a
unsafeFetchKey :: Config -> Key -> IO a
unsafeFetchKey Config
c Key
k = Key -> Config -> IO a
forall a. (FromConfig a, Typeable a) => Key -> Config -> IO a
fetchFromConfig Key
k Config
c
mkConfig :: Text -> IO Config
mkConfig :: Text -> IO Config
mkConfig Text
appName =
Config -> IO Config
forall (f :: * -> *) a. Applicative f => a -> f a
pure Config
emptyConfig
IO Config -> (Config -> IO Config) -> IO Config
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= SourceCreator -> Config -> IO Config
addSource (SourceCreator
Cli.fromConfig)
IO Config -> (Config -> IO Config) -> IO Config
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= SourceCreator -> Config -> IO Config
addSource (Text -> SourceCreator
Env.fromConfig Text
appName)
IO Config -> (Config -> IO Config) -> IO Config
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= SourceCreator -> Config -> IO Config
addSource (Key -> SourceCreator
PropertiesFile.fromConfig Key
"config.file")
mkConfig' :: Defaults -> [SourceCreator] -> IO Config
mkConfig' :: Defaults -> [SourceCreator] -> IO Config
mkConfig' Defaults
defaults [SourceCreator]
sources = [SourceCreator] -> Config -> IO Config
addSources [SourceCreator]
sources (Config -> IO Config) -> (Config -> Config) -> Config -> IO Config
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Defaults -> Config -> Config
addDefaults Defaults
defaults (Config -> IO Config) -> Config -> IO Config
forall a b. (a -> b) -> a -> b
$ Config
emptyConfig