mateamt/app/AppTypes/Configuration.hs

50 lines
1.2 KiB
Haskell
Raw Normal View History

2019-10-27 21:45:07 +00:00
{-# LANGUAGE OverloadedStrings #-}
module AppTypes.Configuration where
import qualified Data.Text as T
import Data.YAML as Y
import Options.Applicative as O
data ServerConfig = ServerConfig
{ configDbHost :: T.Text
, configDbPort :: Word
, configDbName :: T.Text
, configDbUser :: T.Text
, configDbPasswd :: T.Text
, configCurrencySymbol :: T.Text
, configListenPort :: Word
, configListenHost :: T.Text
2020-04-18 22:49:30 +00:00
-- , configMaxConnectionsPerClient :: Word
2019-12-15 09:31:41 +00:00
, configBlockRegistration :: Bool
2019-10-27 21:45:07 +00:00
}
deriving (Show)
instance FromYAML ServerConfig where
parseYAML = withMap "Configuration" $ \m -> ServerConfig
<$> m .: "db_host"
<*> m .: "db_port"
<*> m .: "db_name"
<*> m .: "db_user"
<*> m .: "db_passwd"
<*> m .: "currency"
<*> m .: "listen_port"
<*> m .:? "listen_host" .!= "127.0.0.1"
2020-04-18 22:49:30 +00:00
-- <*> m .:? "max_connections_per_client" .!= 10
2019-12-15 09:31:41 +00:00
<*> m .: "block_registration"
2019-10-27 21:45:07 +00:00
newtype Options = Options
{ optConfigLocation :: T.Text
}
deriving (Show)
options :: O.Parser Options
options = Options
<$> strOption
( long "configuration"
<> short 'c'
<> metavar "FILEPATH"
<> help "Location of the configuration YAML-file"
)