Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Config
- class IConfig config
- data Value a
- getConfigValue :: (IConfig config, MonadThrow m, FromJSON result) => [Text] -> config -> m result
- getConfigValueWith :: (IConfig config, MonadThrow m) => (Value -> Parser result) -> [Text] -> config -> m result
- getSelectedConfigSource :: (IConfig config, MonadThrow m) => [Text] -> config -> m ConfigSource
- getAllConfigSources :: (IConfig config, MonadThrow m) => [Text] -> config -> m (Set ConfigSource)
- data ConfigSource
- data ConfigValue
- data ConfigSpec cmd
- parseConfigSpec :: MonadThrow m => Text -> m (ConfigSpec ())
- readConfigSpec :: Text -> IO (ConfigSpec ())
- readConfigSpecTH :: (Lift k, FromJSON k) => Proxy k -> Text -> ExpQ
- newtype InvalidConfigKeyPath = InvalidConfigKeyPath {}
- data ConfigValueParserFailed = ConfigValueParserFailed {
- inputKeys :: ![Text]
- parserErrorMessage :: !Text
- data UnknownConfigKeyFound = UnknownConfigKeyFound {
- parentKeys :: ![Text]
- keyName :: !Text
- siblingKeys :: ![Text]
- data SubConfigEntryExpected = SubConfigEntryExpected {
- keyName :: !Text
- configValue :: !Value
- data ConfigValueTypeMismatchFound = ConfigValueTypeMismatchFound {}
- newtype ConfigurationFileNotFound = ConfigurationFileNotFound {}
- newtype UnsupportedFileExtensionGiven = UnsupportedFileExtensionGiven {}
- data ConfigInvalidSyntaxFound = ConfigInvalidSyntaxFound {
- configFilepath :: !Text
- parserErrorMessage :: !Text
- data SpecInvalidSyntaxFound = SpecInvalidSyntaxFound {
- specFilepath :: !(Maybe Text)
- parseErrorMessage :: !Text
- resolveDefault :: ConfigSpec cmd -> Config
- resolveFiles :: ConfigSpec cmd -> IO (Config, Vector SomeException)
- resolveEnvPure :: ConfigSpec cmd -> [(Text, Text)] -> Config
- resolveEnv :: ConfigSpec cmd -> IO Config
Config
Use this functions to fetch values from the Etc.Config and cast them to types that make sense in your program
Instances
Eq Config Source # | |
Show Config Source # | |
Semigroup Config Source # | |
Monoid Config Source # | |
IConfig Config Source # | |
Defined in System.Etc.Internal.Config getConfigValue :: (MonadThrow m, FromJSON result) => [Text] -> Config -> m result Source # getConfigValueWith :: MonadThrow m => (Value -> Parser result) -> [Text] -> Config -> m result Source # getAllConfigSources :: MonadThrow m => [Text] -> Config -> m (Set ConfigSource) Source # getSelectedConfigSource :: MonadThrow m => [Text] -> Config -> m ConfigSource Source # |
Instances
IConfig Config Source # | |
Defined in System.Etc.Internal.Config getConfigValue :: (MonadThrow m, FromJSON result) => [Text] -> Config -> m result Source # getConfigValueWith :: MonadThrow m => (Value -> Parser result) -> [Text] -> Config -> m result Source # getAllConfigSources :: MonadThrow m => [Text] -> Config -> m (Set ConfigSource) Source # getSelectedConfigSource :: MonadThrow m => [Text] -> Config -> m ConfigSource Source # |
Instances
Functor Value Source # | |
Applicative Value Source # | |
Eq a => Eq (Value a) Source # | |
Ord a => Ord (Value a) Source # | |
Show a => Show (Value a) Source # | |
IsString a => IsString (Value a) Source # | |
Defined in System.Etc.Internal.Types fromString :: String -> Value a # | |
Generic (Value a) Source # | |
type Rep (Value a) Source # | |
Defined in System.Etc.Internal.Types type Rep (Value a) = D1 (MetaData "Value" "System.Etc.Internal.Types" "etc-0.4.1.0-7q0W6i0k47BIqxo3Mr9o9p" False) (C1 (MetaCons "Plain" PrefixI True) (S1 (MetaSel (Just "fromValue") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a)) :+: C1 (MetaCons "Sensitive" PrefixI True) (S1 (MetaSel (Just "fromValue") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a))) |
:: (IConfig config, MonadThrow m, FromJSON result) | |
=> [Text] | Key to fetch from config map |
-> config | Config record |
-> m result |
Fetches a configuration value from a given key, if key
is not found, you may pick the failure mode via the MonadThrow
interface.
example:
>>>
getConfigValue ["db", "user"] config :: Maybe Text
Just "root">>>
getConfigValue ["db", "password"] config :: Maybe Text
Nothing
:: (IConfig config, MonadThrow m) | |
=> (Value -> Parser result) | JSON Parser function |
-> [Text] | Key to fetch from config map |
-> config | Config record |
-> m result |
Fetches a configuration value from a given key, normally this key will
point to a sub-config JSON object, which is then passed to the given JSON
parser function. If key is not found, you may pick the failure mode via the
MonadThrow
interface.
example:
>>>
import qualified Data.Aeson as JSON
>>>
import qualified Data.Aeson.Types as JSON (Parser)
>>>
connectInfoParser :: JSON.Value -> JSON.Parser DbConnectInfo
>>>
getConfigValueWith connectInfoParser ["db"] config
Just (DbConnectInfo {...})
getSelectedConfigSource :: (IConfig config, MonadThrow m) => [Text] -> config -> m ConfigSource Source #
getAllConfigSources :: (IConfig config, MonadThrow m) => [Text] -> config -> m (Set ConfigSource) Source #
ConfigSpec
Use this functions to read the configuration spec. Remember you can use JSON or YAML(*) filepaths
- The yaml cabal flag must be used to support yaml syntax
data ConfigSource Source #
Instances
Eq ConfigSource Source # | |
Defined in System.Etc.Internal.Types (==) :: ConfigSource -> ConfigSource -> Bool # (/=) :: ConfigSource -> ConfigSource -> Bool # | |
Ord ConfigSource Source # | |
Defined in System.Etc.Internal.Types compare :: ConfigSource -> ConfigSource -> Ordering # (<) :: ConfigSource -> ConfigSource -> Bool # (<=) :: ConfigSource -> ConfigSource -> Bool # (>) :: ConfigSource -> ConfigSource -> Bool # (>=) :: ConfigSource -> ConfigSource -> Bool # max :: ConfigSource -> ConfigSource -> ConfigSource # min :: ConfigSource -> ConfigSource -> ConfigSource # | |
Show ConfigSource Source # | |
Defined in System.Etc.Internal.Types showsPrec :: Int -> ConfigSource -> ShowS # show :: ConfigSource -> String # showList :: [ConfigSource] -> ShowS # |
data ConfigValue Source #
Instances
Eq ConfigValue Source # | |
Defined in System.Etc.Internal.Types (==) :: ConfigValue -> ConfigValue -> Bool # (/=) :: ConfigValue -> ConfigValue -> Bool # | |
Show ConfigValue Source # | |
Defined in System.Etc.Internal.Types showsPrec :: Int -> ConfigValue -> ShowS # show :: ConfigValue -> String # showList :: [ConfigValue] -> ShowS # | |
Semigroup ConfigValue Source # | |
Defined in System.Etc.Internal.Types (<>) :: ConfigValue -> ConfigValue -> ConfigValue # sconcat :: NonEmpty ConfigValue -> ConfigValue # stimes :: Integral b => b -> ConfigValue -> ConfigValue # | |
Monoid ConfigValue Source # | |
Defined in System.Etc.Internal.Types mempty :: ConfigValue # mappend :: ConfigValue -> ConfigValue -> ConfigValue # mconcat :: [ConfigValue] -> ConfigValue # |
data ConfigSpec cmd Source #
Instances
:: MonadThrow m | |
=> Text | Text to be parsed |
-> m (ConfigSpec ()) | returns ConfigSpec |
Parses a text input into a ConfigSpec
, input can be JSON or YAML (if cabal
flag is set).
:: Text | Filepath where contents are going to be read from and parsed |
-> IO (ConfigSpec ()) | returns ConfigSpec |
Reads contents of a file and parses into a ConfigSpec
, file contents can be
either JSON or YAML (if cabal flag is set).
readConfigSpecTH :: (Lift k, FromJSON k) => Proxy k -> Text -> ExpQ Source #
Reads a specified FilePath
and parses a ConfigSpec
at compilation time.
Exceptions
newtype InvalidConfigKeyPath Source #
Thrown when calling the getConfig
or getConfigWith
functions on a key
that does not exist in the configuration spec
Instances
data ConfigValueParserFailed Source #
Thrown when there is a type mismatch in a JSON parser given via
getConfigWith
ConfigValueParserFailed | |
|
Instances
Eq ConfigValueParserFailed Source # | |
Defined in System.Etc.Internal.Errors | |
Read ConfigValueParserFailed Source # | |
Show ConfigValueParserFailed Source # | |
Defined in System.Etc.Internal.Errors showsPrec :: Int -> ConfigValueParserFailed -> ShowS # show :: ConfigValueParserFailed -> String # showList :: [ConfigValueParserFailed] -> ShowS # | |
Generic ConfigValueParserFailed Source # | |
Defined in System.Etc.Internal.Errors type Rep ConfigValueParserFailed :: * -> * # | |
Exception ConfigValueParserFailed Source # | |
type Rep ConfigValueParserFailed Source # | |
Defined in System.Etc.Internal.Errors type Rep ConfigValueParserFailed = D1 (MetaData "ConfigValueParserFailed" "System.Etc.Internal.Errors" "etc-0.4.1.0-7q0W6i0k47BIqxo3Mr9o9p" False) (C1 (MetaCons "ConfigValueParserFailed" PrefixI True) (S1 (MetaSel (Just "inputKeys") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 [Text]) :*: S1 (MetaSel (Just "parserErrorMessage") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text))) |
data UnknownConfigKeyFound Source #
Thrown when the resolveFile
function finds a key on a configuration
file that is not specified in the given configuration spec
UnknownConfigKeyFound | |
|
Instances
data SubConfigEntryExpected Source #
Thrown when there is a type mismatch on a configuration entry, specifically, when there is a raw value instead of a sub-config in a configuration file
SubConfigEntryExpected | |
|
Instances
Eq SubConfigEntryExpected Source # | |
Defined in System.Etc.Internal.Errors | |
Read SubConfigEntryExpected Source # | |
Show SubConfigEntryExpected Source # | |
Defined in System.Etc.Internal.Errors showsPrec :: Int -> SubConfigEntryExpected -> ShowS # show :: SubConfigEntryExpected -> String # showList :: [SubConfigEntryExpected] -> ShowS # | |
Generic SubConfigEntryExpected Source # | |
Defined in System.Etc.Internal.Errors type Rep SubConfigEntryExpected :: * -> * # | |
Exception SubConfigEntryExpected Source # | |
type Rep SubConfigEntryExpected Source # | |
Defined in System.Etc.Internal.Errors type Rep SubConfigEntryExpected = D1 (MetaData "SubConfigEntryExpected" "System.Etc.Internal.Errors" "etc-0.4.1.0-7q0W6i0k47BIqxo3Mr9o9p" False) (C1 (MetaCons "SubConfigEntryExpected" PrefixI True) (S1 (MetaSel (Just "keyName") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text) :*: S1 (MetaSel (Just "configValue") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Value))) |
data ConfigValueTypeMismatchFound Source #
This error is thrown when a type mismatch is found in a raw value when
calling resolveFile
ConfigValueTypeMismatchFound | |
|
Instances
newtype ConfigurationFileNotFound Source #
Thrown when a specified configuration file is not found in the system
ConfigurationFileNotFound | |
|
Instances
Eq ConfigurationFileNotFound Source # | |
Defined in System.Etc.Internal.Errors | |
Read ConfigurationFileNotFound Source # | |
Show ConfigurationFileNotFound Source # | |
Defined in System.Etc.Internal.Errors showsPrec :: Int -> ConfigurationFileNotFound -> ShowS # show :: ConfigurationFileNotFound -> String # showList :: [ConfigurationFileNotFound] -> ShowS # | |
Generic ConfigurationFileNotFound Source # | |
Defined in System.Etc.Internal.Errors type Rep ConfigurationFileNotFound :: * -> * # | |
Exception ConfigurationFileNotFound Source # | |
type Rep ConfigurationFileNotFound Source # | |
Defined in System.Etc.Internal.Errors type Rep ConfigurationFileNotFound = D1 (MetaData "ConfigurationFileNotFound" "System.Etc.Internal.Errors" "etc-0.4.1.0-7q0W6i0k47BIqxo3Mr9o9p" True) (C1 (MetaCons "ConfigurationFileNotFound" PrefixI True) (S1 (MetaSel (Just "configFilepath") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Text))) |
newtype UnsupportedFileExtensionGiven Source #
Thrown when an input configuration file contains an unsupported file extension
UnsupportedFileExtensionGiven | |
|
Instances
Eq UnsupportedFileExtensionGiven Source # | |
Read UnsupportedFileExtensionGiven Source # | |
Show UnsupportedFileExtensionGiven Source # | |
Defined in System.Etc.Internal.Errors showsPrec :: Int -> UnsupportedFileExtensionGiven -> ShowS # show :: UnsupportedFileExtensionGiven -> String # showList :: [UnsupportedFileExtensionGiven] -> ShowS # | |
Generic UnsupportedFileExtensionGiven Source # | |
Defined in System.Etc.Internal.Errors type Rep UnsupportedFileExtensionGiven :: * -> * # | |
Exception UnsupportedFileExtensionGiven Source # | |
type Rep UnsupportedFileExtensionGiven Source # | |
Defined in System.Etc.Internal.Errors type Rep UnsupportedFileExtensionGiven = D1 (MetaData "UnsupportedFileExtensionGiven" "System.Etc.Internal.Errors" "etc-0.4.1.0-7q0W6i0k47BIqxo3Mr9o9p" True) (C1 (MetaCons "UnsupportedFileExtensionGiven" PrefixI True) (S1 (MetaSel (Just "configFilepath") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Text))) |
data ConfigInvalidSyntaxFound Source #
Thrown when an input configuration file contains invalid syntax
ConfigInvalidSyntaxFound | |
|
Instances
Eq ConfigInvalidSyntaxFound Source # | |
Defined in System.Etc.Internal.Errors | |
Read ConfigInvalidSyntaxFound Source # | |
Show ConfigInvalidSyntaxFound Source # | |
Defined in System.Etc.Internal.Errors showsPrec :: Int -> ConfigInvalidSyntaxFound -> ShowS # show :: ConfigInvalidSyntaxFound -> String # showList :: [ConfigInvalidSyntaxFound] -> ShowS # | |
Generic ConfigInvalidSyntaxFound Source # | |
Defined in System.Etc.Internal.Errors type Rep ConfigInvalidSyntaxFound :: * -> * # | |
Exception ConfigInvalidSyntaxFound Source # | |
type Rep ConfigInvalidSyntaxFound Source # | |
Defined in System.Etc.Internal.Errors type Rep ConfigInvalidSyntaxFound = D1 (MetaData "ConfigInvalidSyntaxFound" "System.Etc.Internal.Errors" "etc-0.4.1.0-7q0W6i0k47BIqxo3Mr9o9p" False) (C1 (MetaCons "ConfigInvalidSyntaxFound" PrefixI True) (S1 (MetaSel (Just "configFilepath") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text) :*: S1 (MetaSel (Just "parserErrorMessage") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text))) |
data SpecInvalidSyntaxFound Source #
Thrown when an configuration spec file contains invalid syntax
SpecInvalidSyntaxFound | |
|
Instances
Eq SpecInvalidSyntaxFound Source # | |
Defined in System.Etc.Internal.Errors | |
Read SpecInvalidSyntaxFound Source # | |
Show SpecInvalidSyntaxFound Source # | |
Defined in System.Etc.Internal.Errors showsPrec :: Int -> SpecInvalidSyntaxFound -> ShowS # show :: SpecInvalidSyntaxFound -> String # showList :: [SpecInvalidSyntaxFound] -> ShowS # | |
Generic SpecInvalidSyntaxFound Source # | |
Defined in System.Etc.Internal.Errors type Rep SpecInvalidSyntaxFound :: * -> * # | |
Exception SpecInvalidSyntaxFound Source # | |
type Rep SpecInvalidSyntaxFound Source # | |
Defined in System.Etc.Internal.Errors type Rep SpecInvalidSyntaxFound = D1 (MetaData "SpecInvalidSyntaxFound" "System.Etc.Internal.Errors" "etc-0.4.1.0-7q0W6i0k47BIqxo3Mr9o9p" False) (C1 (MetaCons "SpecInvalidSyntaxFound" PrefixI True) (S1 (MetaSel (Just "specFilepath") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Maybe Text)) :*: S1 (MetaSel (Just "parseErrorMessage") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text))) |
Resolvers
Use this functions to gather configuration values from different sources (environment variables, command lines or files). Then compose results together using the mappend function
:: ConfigSpec cmd | ConfigSpec |
-> Config | returns Configuration Map with default values included |
Gathers all default values from the etc/spec
entries inside a ConfigSpec
:: ConfigSpec cmd | Config Spec |
-> IO (Config, Vector SomeException) | Configuration Map with all values from files filled in and a list of warnings |
Gathers configuration values from a list of files specified on the
etc/filepaths
entry of a Config Spec. This will return a Configuration Map
with values from all filepaths merged in, and a list of errors in case there was
an error reading one of the filepaths.
:: ConfigSpec cmd | ConfigSpec |
-> [(Text, Text)] | Environment Variable tuples |
-> Config | returns Configuration Map with Environment Variables values filled in |
Gathers all OS Environment Variable values (env
entries) from the etc/spec
entries inside a ConfigSpec
. This version of the function gathers the input
from a list of tuples rather than the OS.
:: ConfigSpec cmd | Config Spec |
-> IO Config | returns Configuration Map with Environment Variables values filled in |
Gathers all OS Environment Variable values (env
entries) from the etc/spec
entries inside a ConfigSpec