Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,33 @@
|
|||
import Data.Char
|
||||
import Data.List
|
||||
import Data.List.Split
|
||||
|
||||
main :: IO ()
|
||||
main = readFile "config" >>= (print . parseConfig)
|
||||
|
||||
parseConfig :: String -> Config
|
||||
parseConfig = foldr addConfigValue defaultConfig . clean . lines
|
||||
where clean = filter (not . flip any ["#", ";", "", " "] . (==) . take 1)
|
||||
|
||||
addConfigValue :: String -> Config -> Config
|
||||
addConfigValue raw config = case key of
|
||||
"fullname" -> config {fullName = values}
|
||||
"favouritefruit" -> config {favoriteFruit = values}
|
||||
"needspeeling" -> config {needsPeeling = True}
|
||||
"seedsremoved" -> config {seedsRemoved = True}
|
||||
"otherfamily" -> config {otherFamily = splitOn "," values}
|
||||
_ -> config
|
||||
where (k, vs) = span (/= ' ') raw
|
||||
key = map toLower k
|
||||
values = tail vs
|
||||
|
||||
data Config = Config
|
||||
{ fullName :: String
|
||||
, favoriteFruit :: String
|
||||
, needsPeeling :: Bool
|
||||
, seedsRemoved :: Bool
|
||||
, otherFamily :: [String]
|
||||
} deriving (Show)
|
||||
|
||||
defaultConfig :: Config
|
||||
defaultConfig = Config "" "" False False []
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import Data.ConfigFile
|
||||
import Data.Either.Utils
|
||||
|
||||
getSetting cp x = forceEither $ get cp "Default" x
|
||||
|
||||
cp <- return . forceEither =<< readfile emptyCP "name_of_configuration_file"
|
||||
let username = getSetting cp "username"
|
||||
password = getSetting cp "password"
|
||||
Loading…
Add table
Add a link
Reference in a new issue