{-# 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 , configCurrencyFraction :: Word , configListenPort :: Word , configListenHost :: T.Text -- , configMaxConnectionsPerClient :: Word , configBlockRegistration :: Bool , configSendmailPath :: FilePath } deriving (Show) instance FromJSON ServerConfig where parseJSON (Object m) = ServerConfig <$> m .: "db_host" <*> m .: "db_port" <*> m .: "db_name" <*> m .: "db_user" <*> m .: "db_passwd" <*> m .: "currency" <*> m .: "currency_fraction" <*> m .: "listen_port" <*> m .:? "listen_host" .!= "127.0.0.1" -- <*> m .:? "max_connections_per_client" .!= 10 <*> m .: "block_registration" <*> m .: "sendmail_path" data Options = Options { optConfigLocation :: T.Text , optMigrationLocation :: T.Text } deriving (Show) options :: O.Parser Options options = Options <$> strOption ( long "configuration" <> short 'c' <> metavar "FILEPATH" <> help "Location of the configuration YAML-file" ) <*> strOption ( long "migration-dir" <> short 'm' <> metavar "DIRPATH" <> help "Location of the migration scripts folder" <> value "./migration_scripts" <> showDefault )