gdritter repos config-ini / 5722b51
A few formatting fixes + a rename Getty Ritter 7 years ago
2 changed file(s) with 21 addition(s) and 17 deletion(s). Collapse all Expand all
6565 let v = getIniValue p
6666 print v
6767 putStrLn "------------------------"
68 putStr (unpack (getIniText configSpec))
68 putStr (unpack (serializeIni configSpec))
6969 putStrLn "------------------------"
7070 let v' = v { _confPort = 9191
7171 , _confHostname = "argl"
7777 [ "value added by application" ]
7878 , updateIgnoreExtraneousFields = False
7979 }
80 let up = getIniText $ updateIni v' $ setIniUpdatePolicy pol p
80 let up = serializeIni $ updateIni v' $ setIniUpdatePolicy pol p
8181 putStrLn "------------------------"
8282 putStr (unpack up)
8383 putStrLn "------------------------"
1515 Ini
1616 , ini
1717 , getIniValue
18 , getRawIni
1819 -- ** Parsing INI files
1920 , parseIni
2021 -- ** Serializing INI files
21 , getIniText
22 , serializeIni
2223 -- ** Updating INI Files
2324 , updateIni
2425 , setIniUpdatePolicy
2526 , UpdatePolicy(..)
2627 , UpdateCommentPolicy(..)
2728 , defaultUpdatePolicy
28
2929 -- * Bidirectional Parser Types
3030 -- $types
3131 , IniSpec
156156 -- value was created directly from a value and a specification, then
157157 -- it will pretty-print an initial version of the file with the
158158 -- comments and placeholder text specified in the spec.
159 getIniText :: Ini s -> Text
160 getIniText = printRawIni . getRawIni
159 serializeIni :: Ini s -> Text
160 serializeIni = printRawIni . getRawIni
161161
162162 -- | Get the underlying 'RawIni' value for the file.
163163 getRawIni :: Ini s -> RawIni
247247 allOptional :: (Seq (Field s)) -> Bool
248248 allOptional = all isOptional
249249 where isOptional (Field _ fd) = fdSkipIfMissing fd
250 isOptional (FieldMb _ fd) = fdSkipIfMissing fd
250 isOptional (FieldMb _ _) = True
251251
252252 data Section s = Section NormalizedText (Seq (Field s)) Bool
253253
352352 -- values associated with that field.
353353 field :: Text -> FieldValue a -> FieldDescription a
354354 field name value = FieldDescription
355 { fdName = normalize name
355 { fdName = normalize (name <> " ")
356356 , fdValue = value
357357 , fdComment = Seq.empty
358358 , fdDummy = Nothing
510510 , vDelimiter = '='
511511 }
512512 )
513 toVal (Field l descr) =
514 mkIniValue (fvEmit (fdValue descr) (get l s)) descr False
515 toVal (FieldMb l descr) =
516 case get l s of
517 Nothing ->
513 toVal (Field l descr)
514 | Just dummy <- fdDummy descr =
515 mkIniValue dummy descr False
516 | otherwise =
517 mkIniValue (fvEmit (fdValue descr) (get l s)) descr False
518 toVal (FieldMb l descr)
519 | Just dummy <- fdDummy descr =
520 mkIniValue dummy descr True
521 | Just v <- get l s =
522 mkIniValue (fvEmit (fdValue descr) v) descr True
523 | otherwise =
518524 mkIniValue "" descr True
519 Just v ->
520 mkIniValue (fvEmit (fdValue descr) v) descr True
521525
522526 -- | An 'UpdatePolicy' describes how to
523527 data UpdatePolicy = UpdatePolicy
584588 --doUpdateIni :: s -> s -> Spec s -> RawIni -> UpdatePolicy -> Either String (Ini s)
585589 doUpdateIni :: s -> Ini s -> Either String (Ini s)
586590 doUpdateIni s i@Ini { iniSpec = spec
587 , iniDef = def
591 , iniDef = def
588592 , iniPol = pol
589593 } = do -- spec (RawIni ini) pol = do
590594 let RawIni ini' = getRawIni i
756760 mkComments cs
757761 val = IniValue
758762 { vLineNo = 0
759 , vName = actualText t <> " "
763 , vName = actualText t
760764 , vValue = ""
761765 , vComments = comments
762766 , vCommentedOut = False