add config
This commit is contained in:
parent
712008105d
commit
b7e88fcfc9
45
lib/Config.hs
Normal file
45
lib/Config.hs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
module Config
|
||||||
|
( parserOpts
|
||||||
|
, AppConfig(..)
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Options.Applicative
|
||||||
|
import Data.Text (Text)
|
||||||
|
|
||||||
|
data AppConfig = AppConfig
|
||||||
|
{ appPort :: Int
|
||||||
|
, appDbFile :: FilePath
|
||||||
|
, appUser :: Text
|
||||||
|
, appPassHash :: Text
|
||||||
|
} deriving (Show, Eq)
|
||||||
|
|
||||||
|
appConfig :: Parser AppConfig
|
||||||
|
appConfig = AppConfig
|
||||||
|
<$> option auto
|
||||||
|
( long "port"
|
||||||
|
<> help "port to listen"
|
||||||
|
<> showDefault
|
||||||
|
<> value 8000
|
||||||
|
<> metavar "INT")
|
||||||
|
<*> strOption
|
||||||
|
( long "dbpath"
|
||||||
|
<> help "sqlite db file path"
|
||||||
|
<> showDefault
|
||||||
|
<> value "quotes.db"
|
||||||
|
<> metavar "TARGET")
|
||||||
|
<*> strOption
|
||||||
|
( long "user"
|
||||||
|
<> help "basic auth user (for writes)"
|
||||||
|
<> showDefault
|
||||||
|
<> value "root"
|
||||||
|
<> metavar "USER")
|
||||||
|
<*> strOption
|
||||||
|
( long "password"
|
||||||
|
<> help "password hash for basic auth user, generate with argon2")
|
||||||
|
|
||||||
|
parserOpts :: ParserInfo AppConfig
|
||||||
|
parserOpts = info (appConfig <**> helper)
|
||||||
|
( fullDesc
|
||||||
|
<> progDesc "Serve Quotes API"
|
||||||
|
<> header "quotes api" )
|
Loading…
Reference in New Issue
Block a user