about summary refs log tree commit diff
path: root/src/Main.hs
blob: a50ca67ed17d7a1b8bb2dfaf9219ed2c8d73f98e (plain) (blame)
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 Main where

import           Control.Applicative          (pure, (<$>), (<*>))
import           Control.Exception            (bracket)
import           Data.Acid
import           Data.Acid.Local (createCheckpointAndClose)
import           Options

import           BlogDB                       (initialBlogState)
import           Locales                      (version)
import           Server

{- Server -}

data MainOptions = MainOptions {
  optState :: String,
  optPort  :: Int,
  optRes   :: String
}

instance Options MainOptions where
  defineOptions = pure MainOptions
    <*> simpleOption "statedir" "/var/tazblog/"
        "Directory in which the BlogState is located."
    <*> simpleOption "port" 8000
        "Port to run on. Default is 8000."
    <*> simpleOption "res" "/usr/share/tazblog/res"
        "Resources folder location."
        
main :: IO()
main = do
    putStrLn ("TazBlog " ++ version ++ " in Haskell starting")
    runCommand $ \opts args ->
      bracket (openLocalStateFrom (optState opts ++ "BlogState") initialBlogState)
              createCheckpointAndClose
              (\acid -> runBlog acid (optPort opts) (optRes opts))