blob: bba067d53afc3961a9d49c355b879a49b0224804 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
module Thermoprint.Server
( thermoprintServer
, module Data.Default
) where
import Data.Default
import qualified Config.Dyre as Dyre
import System.IO (hPutStrLn, stderr)
import System.Exit (exitFailure)
import Control.Monad ((<=<))
data Config = Config { dyreError :: Maybe String
}
instance Default Config where
def = Config { dyreError = Nothing
}
thermoprintServer :: Config -> IO ()
thermoprintServer = Dyre.wrapMain $ Dyre.defaultParams
{ Dyre.projectName = "thermoprint-server"
, Dyre.realMain = realMain <=< handleDyreErrors
, Dyre.showError = (\cfg msg -> cfg { dyreError = Just msg })
}
handleDyreErrors :: Config -> IO Config
handleDyreErrors cfg
| Just msg <- dyreError cfg = do
hPutStrLn stderr msg
exitFailure
return undefined
| otherwise = return cfg
realMain :: Config -> IO ()
realMain _ = undefined
|