diff options
Diffstat (limited to 'src/Config.hs')
-rw-r--r-- | src/Config.hs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Config.hs b/src/Config.hs index 0a421fa..98e2c9a 100644 --- a/src/Config.hs +++ b/src/Config.hs @@ -12,6 +12,7 @@ import qualified Data.Map as M import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.IO as T +import Data.Text.Read (decimal) import Control.Monad (guard) @@ -35,6 +36,7 @@ configUsage = , " - url (required)" , " - mailTo (optional)" , " - properties (optional)" + , " - waitInMinutes (optional, default to 1)" , "" , " Example:" , "" @@ -46,6 +48,9 @@ configUsage = , "" , " # The properties field is an optional list" , " # properties = cp, city, surface, ges" + , "" + , " # The waitInMinutes field is an optional integer, default to 1" + , " # waitInMinutes = 60" ] configPath :: FilePath @@ -79,9 +84,14 @@ configFromMap map = do { url = url , mailTo = fieldValues "mailTo" map , properties = fieldValues "properties" map + , waitInMinutes = fromMaybe 1 $ M.lookup "waitInMinutes" map >>= fmap fst . eitherToMaybe . decimal } return config +eitherToMaybe :: Either a b -> Maybe b +eitherToMaybe (Right x) = Just x +eitherToMaybe _ = Nothing + fieldValues :: Text -> Map Text Text -> [Text] fieldValues field map = fromMaybe [] $ fmap T.strip . T.splitOn "," <$> M.lookup field map |