mateamt/app/AppTypes/Configuration.hs

59 lines
1.4 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
2020-05-16 14:12:49 +00:00
data Options = Options
2019-10-27 21:45:07 +00:00
{ optConfigLocation :: T.Text
2020-05-16 14:12:49 +00:00
, optMigrationLocation :: T.Text
2019-10-27 21:45:07 +00:00
}
deriving (Show)
options :: O.Parser Options
options = Options
<$> strOption
( long "configuration"
<> short 'c'
<> metavar "FILEPATH"
<> help "Location of the configuration YAML-file"
)
2020-05-16 14:12:49 +00:00
<*> strOption
( long "migration-dir"
<> short 'm'
<> metavar "DIRPATH"
<> help "Location of the migration scripts folder"
<> value "./migration_scripts"
<> showDefault
)