feat: add --db-path CLI option and open SQLite db on startup
This commit is contained in:
+11
@@ -10,11 +10,13 @@ import Network.Wai.Handler.Warp qualified as Warp
|
||||
import Options.Applicative qualified as Opt
|
||||
import System.Posix.Signals qualified as Signals
|
||||
|
||||
import Sis.Database qualified as Database
|
||||
import Sis.Server qualified as Sis
|
||||
|
||||
data Options = Options
|
||||
{ optPort :: Int
|
||||
, optStaticDir :: FilePath
|
||||
, optDbPath :: FilePath
|
||||
}
|
||||
|
||||
optionsParser :: Opt.Parser Options
|
||||
@@ -36,6 +38,13 @@ optionsParser =
|
||||
<> Opt.value "frontend/dist"
|
||||
<> Opt.showDefault
|
||||
)
|
||||
<*> Opt.strOption
|
||||
( Opt.long "db-path"
|
||||
<> Opt.metavar "PATH"
|
||||
<> Opt.help "Path to the SQLite database file"
|
||||
<> Opt.value "data/sis.db"
|
||||
<> Opt.showDefault
|
||||
)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
@@ -46,6 +55,8 @@ main = do
|
||||
<> Opt.progDesc "Sis — shared household chore tracker"
|
||||
<> Opt.header "sis-server"
|
||||
|
||||
_db <- Database.openDatabase (optDbPath opts)
|
||||
|
||||
-- Install a SIGTERM handler so Docker stop works cleanly.
|
||||
_ <-
|
||||
Signals.installHandler
|
||||
|
||||
Reference in New Issue
Block a user