Stability | unstable |
---|---|
Portability | portable |
Safe Haskell | Safe |
Language | Haskell98 |
System.Config.File
Description
Synopsis
- type Key = String
- type Value = String
- data Configuration
- withConfiguration :: String -> (Configuration -> IO b) -> IO b
- loadConfiguration :: String -> IO Configuration
- saveConfiguration :: Configuration -> IO ()
- loadGlobal :: FilePath -> IO Configuration
- loadLocal :: FilePath -> IO Configuration
- hasV :: Configuration -> Key -> Bool
- getV :: Configuration -> Key -> Maybe Value
- removeV :: Configuration -> Key -> Configuration
- replaceV :: Configuration -> Key -> Value -> Configuration
- type InteractiveValidator = Value -> IO (Either String Value)
- acceptNonBlank :: InteractiveValidator
- acceptAnything :: InteractiveValidator
- fillInteractively :: Configuration -> [(Key, InteractiveValidator)] -> IO Configuration
- fillInteractivelyWhen :: (Configuration -> Bool) -> Configuration -> [(Key, InteractiveValidator)] -> IO Configuration
- newC :: Configuration -> Bool
- emptyC :: Configuration -> Bool
Basics
Types
data Configuration Source #
While the internal representation is not exposed directly, an implementation
of the Show
instance is provided in order to dump the configuration when that
may be aidful in debugging. However, you will only see the key values stored
inside the Map
Instances
Show Configuration Source # | |
Defined in System.Config.File Methods showsPrec :: Int -> Configuration -> ShowS # show :: Configuration -> String # showList :: [Configuration] -> ShowS # |
Managing
Arguments
:: String | Configuration file name |
-> (Configuration -> IO b) | |
-> IO b |
Deprecated: Use loadLocal/loadGlobal instead
However if you like to stack software ala withSocketsDo $ withX $ withY
this might not
be your preferred approach. You could go with the following approach, which was excluded for
library portability:
{-# LANGUAGE ImplicitParams, RankNTypes #-} import System.Config.File withConfigurationImplicit :: String -> ((?configuration :: Configuration) => IO b) -> IO b withConfigurationImplicit filename f = withConfiguration filename (\c -> let ?configuration = c in f) main = withConfigurationImplicit ".apprc" $ do print $ hasV "name" ?configuration print $ getV "name" ?configuration
Arguments
:: String | Configuration file name |
-> IO Configuration |
Deprecated: Use loadLocal/loadGlobal instead
saveConfiguration :: Configuration -> IO () Source #
The configuration will be saved into the same file it was read from, obviously
loadGlobal :: FilePath -> IO Configuration Source #
CRUD
removeV :: Configuration -> Key -> Configuration Source #
replaceV :: Configuration -> Key -> Value -> Configuration Source #
Data "entry"
It proved useful that for a few small cases to also have a way to "build" the configuration interactively. When you consider easy to validate fields (that don't depend on other fields), it seems to be worth to have this functionality included.
Validation
type InteractiveValidator = Value -> IO (Either String Value) Source #
Via the Left
data constructor we are able to pass the message necessary to
notify the user that the inputed data is not valid
Execution
fillInteractively :: Configuration -> [(Key, InteractiveValidator)] -> IO Configuration Source #
Request user input for the set of (Key, InteractiveValidator). For keys that are
already set in the Configuration
, values will be overwritten
fillInteractivelyWhen :: (Configuration -> Bool) -> Configuration -> [(Key, InteractiveValidator)] -> IO Configuration Source #
Execution dependent on a predicate
Predicates
newC :: Configuration -> Bool Source #
Has this configuration just been created?
emptyC :: Configuration -> Bool Source #
Configuration doesn't contain any values?