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 Options.Applicative qualified as Opt
|
||||||
import System.Posix.Signals qualified as Signals
|
import System.Posix.Signals qualified as Signals
|
||||||
|
|
||||||
|
import Sis.Database qualified as Database
|
||||||
import Sis.Server qualified as Sis
|
import Sis.Server qualified as Sis
|
||||||
|
|
||||||
data Options = Options
|
data Options = Options
|
||||||
{ optPort :: Int
|
{ optPort :: Int
|
||||||
, optStaticDir :: FilePath
|
, optStaticDir :: FilePath
|
||||||
|
, optDbPath :: FilePath
|
||||||
}
|
}
|
||||||
|
|
||||||
optionsParser :: Opt.Parser Options
|
optionsParser :: Opt.Parser Options
|
||||||
@@ -36,6 +38,13 @@ optionsParser =
|
|||||||
<> Opt.value "frontend/dist"
|
<> Opt.value "frontend/dist"
|
||||||
<> Opt.showDefault
|
<> 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 :: IO ()
|
||||||
main = do
|
main = do
|
||||||
@@ -46,6 +55,8 @@ main = do
|
|||||||
<> Opt.progDesc "Sis — shared household chore tracker"
|
<> Opt.progDesc "Sis — shared household chore tracker"
|
||||||
<> Opt.header "sis-server"
|
<> Opt.header "sis-server"
|
||||||
|
|
||||||
|
_db <- Database.openDatabase (optDbPath opts)
|
||||||
|
|
||||||
-- Install a SIGTERM handler so Docker stop works cleanly.
|
-- Install a SIGTERM handler so Docker stop works cleanly.
|
||||||
_ <-
|
_ <-
|
||||||
Signals.installHandler
|
Signals.installHandler
|
||||||
|
|||||||
Reference in New Issue
Block a user