(optionally) read config path from cmdline arguments

master
rnhmjoj 2017-02-21 17:00:30 +01:00
parent 56b0689b04
commit f29cdcb3c2
No known key found for this signature in database
GPG Key ID: 362BB82B7E496B7C
2 changed files with 11 additions and 5 deletions

View File

@ -29,10 +29,13 @@ createEmptyIfMissing file = do
when (not exists) (writeFile file "") when (not exists) (writeFile file "")
settings :: IO AppSettings settings :: Maybe FilePath -> IO AppSettings
settings = do settings path = do
urlsPath <- getUserDataFile "breve" "" configPath <- case path of
configPath <- getUserConfigFile "breve" "" Just path -> return path
Nothing -> getUserConfigFile "breve" ""
urlsPath <- getUserDataFile "breve" ""
config <- load [Required configPath] config <- load [Required configPath]
host <- lookupDefault "localhost" config "hostname" host <- lookupDefault "localhost" config "hostname"

View File

@ -5,8 +5,10 @@ import Breve.Settings
import Breve.UrlTable import Breve.UrlTable
import Data.Text (Text, unpack) import Data.Text (Text, unpack)
import Data.Maybe (listToMaybe)
import Control.Concurrent (forkIO) import Control.Concurrent (forkIO)
import Control.Monad import Control.Monad
import System.Environment (getArgs)
import Web.Spock.Core import Web.Spock.Core
import Network.Wai.Handler.WarpTLS (runTLS, TLSSettings) import Network.Wai.Handler.WarpTLS (runTLS, TLSSettings)
@ -28,7 +30,8 @@ forkIO' = fmap (const ()) . forkIO
main :: IO () main :: IO ()
main = do main = do
AppSettings {..} <- settings configPath <- fmap listToMaybe getArgs
AppSettings {..} <- settings configPath
table <- load urlTable table <- load urlTable
when (bindPort == 443) (forkIO' $ runTLSRedirect bindHost) when (bindPort == 443) (forkIO' $ runTLSRedirect bindHost)