| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
System.Etc
Contents
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
- data ConfigurationError
- parseConfigSpec :: MonadThrow m => Text -> m (ConfigSpec ())
- readConfigSpec :: Text -> IO (ConfigSpec ())
- 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 # | |
| Show Config # | |
| Semigroup Config # | |
| Monoid Config # | |
| IConfig Config # | |
Defined in System.Etc.Internal.Config Methods getConfigValue :: (MonadThrow m, FromJSON result) => [Text] -> Config -> m result # getConfigValueWith :: MonadThrow m => (Value -> Parser result) -> [Text] -> Config -> m result # getAllConfigSources :: MonadThrow m => [Text] -> Config -> m (Set ConfigSource) # getSelectedConfigSource :: MonadThrow m => [Text] -> Config -> m ConfigSource # | |
Minimal complete definition
getConfigValue, getConfigValueWith, getAllConfigSources, getSelectedConfigSource
Instances
| IConfig Config # | |
Defined in System.Etc.Internal.Config Methods getConfigValue :: (MonadThrow m, FromJSON result) => [Text] -> Config -> m result # getConfigValueWith :: MonadThrow m => (Value -> Parser result) -> [Text] -> Config -> m result # getAllConfigSources :: MonadThrow m => [Text] -> Config -> m (Set ConfigSource) # getSelectedConfigSource :: MonadThrow m => [Text] -> Config -> m ConfigSource # | |
Instances
| Functor Value # | |
| Applicative Value # | |
| Eq a => Eq (Value a) # | |
| Ord a => Ord (Value a) # | |
Defined in System.Etc.Internal.Types | |
| Show a => Show (Value a) # | |
| IsString a => IsString (Value a) # | |
Defined in System.Etc.Internal.Types Methods fromString :: String -> Value a # | |
| Generic (Value a) # | |
| type Rep (Value a) # | |
Defined in System.Etc.Internal.Types type Rep (Value a) = D1 (MetaData "Value" "System.Etc.Internal.Types" "etc-0.4.0.3-1VdOfTC1BjK5K2oA1bREav" 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))) | |
Arguments
| :: (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 TextJust "root">>>getConfigValue ["db", "password"] config :: Maybe TextNothing
Arguments
| :: (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"] configJust (DbConnectInfo {...})
getSelectedConfigSource :: (IConfig config, MonadThrow m) => [Text] -> config -> m ConfigSource #
getAllConfigSources :: (IConfig config, MonadThrow m) => [Text] -> config -> m (Set ConfigSource) #
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 #
Constructors
| File | |
Fields
| |
| Env | |
| Cli | |
| Default | |
| None | |
Instances
| Eq ConfigSource # | |
Defined in System.Etc.Internal.Types | |
| Ord ConfigSource # | |
Defined in System.Etc.Internal.Types Methods 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 # | |
Defined in System.Etc.Internal.Types Methods showsPrec :: Int -> ConfigSource -> ShowS # show :: ConfigSource -> String # showList :: [ConfigSource] -> ShowS # | |
data ConfigValue #
Instances
| Eq ConfigValue # | |
Defined in System.Etc.Internal.Types | |
| Show ConfigValue # | |
Defined in System.Etc.Internal.Types Methods showsPrec :: Int -> ConfigValue -> ShowS # show :: ConfigValue -> String # showList :: [ConfigValue] -> ShowS # | |
| Semigroup ConfigValue # | |
Defined in System.Etc.Internal.Types Methods (<>) :: ConfigValue -> ConfigValue -> ConfigValue # sconcat :: NonEmpty ConfigValue -> ConfigValue # stimes :: Integral b => b -> ConfigValue -> ConfigValue # | |
| Monoid ConfigValue # | |
Defined in System.Etc.Internal.Types Methods mempty :: ConfigValue # mappend :: ConfigValue -> ConfigValue -> ConfigValue # mconcat :: [ConfigValue] -> ConfigValue # | |
data ConfigSpec cmd #
Instances
| Eq cmd => Eq (ConfigSpec cmd) # | |
Defined in System.Etc.Internal.Spec.Types Methods (==) :: ConfigSpec cmd -> ConfigSpec cmd -> Bool # (/=) :: ConfigSpec cmd -> ConfigSpec cmd -> Bool # | |
| Show cmd => Show (ConfigSpec cmd) # | |
Defined in System.Etc.Internal.Spec.Types Methods showsPrec :: Int -> ConfigSpec cmd -> ShowS # show :: ConfigSpec cmd -> String # showList :: [ConfigSpec cmd] -> ShowS # | |
| FromJSON cmd => FromJSON (ConfigSpec cmd) # | |
Defined in System.Etc.Internal.Spec.Types Methods parseJSON :: Value -> Parser (ConfigSpec cmd) # parseJSONList :: Value -> Parser [ConfigSpec cmd] # | |
data ConfigurationError #
Constructors
| InvalidConfiguration !(Maybe Text) !Text | |
| InvalidConfigKeyPath ![Text] | |
| ConfigurationFileNotFound !Text |
Instances
Arguments
| :: 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).
Arguments
| :: 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).
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
Arguments
| :: ConfigSpec cmd | ConfigSpec |
| -> Config | returns Configuration Map with default values included |
Gathers all default values from the etc/spec entries inside a ConfigSpec
Arguments
| :: 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.
Arguments
| :: 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.
Arguments
| :: 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