minimal-configuration-0.1.3: Minimal ini like configuration library with a few extras

Stabilityunstable
Portabilityportable
Safe HaskellSafe
LanguageHaskell98

System.Config.File

Contents

Description

 

Synopsis

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

Managing

withConfiguration Source

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

loadConfiguration Source

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

CRUD

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?