* removed System.Environment from Main.hs

* using the brand-new Options package to parse command line options (--port and --statedir)
This commit is contained in:
Vincent Ambo 2012-03-25 19:29:38 +02:00
parent 74ce7d9bf0
commit 8b64d14a72

View file

@ -24,7 +24,7 @@ import Data.Time
import Data.SafeCopy (base, deriveSafeCopy) import Data.SafeCopy (base, deriveSafeCopy)
import Happstack.Server hiding (Session) import Happstack.Server hiding (Session)
import Happstack.Server.Compression import Happstack.Server.Compression
import System.Environment(getEnv) import Options
import System.Locale (defaultTimeLocale) import System.Locale (defaultTimeLocale)
import Blog import Blog
@ -34,16 +34,23 @@ import RSS
{- Server -} {- Server -}
defineOptions "MainOptions" $ do
stringOption "optState" "statedir" "../"
"Directory in which the /BlogState dir is located.\
\ The default is ../ (if run from src/)"
intOption "optPort" "port" 8000
"The port to run the web server on. Default is 8000"
tmpPolicy :: BodyPolicy tmpPolicy :: BodyPolicy
tmpPolicy = (defaultBodyPolicy "./tmp/" 0 200000 1000) tmpPolicy = (defaultBodyPolicy "./tmp/" 0 200000 1000)
main :: IO() main :: IO()
main = do main = do
putStrLn ("TazBlog " ++ version ++ " in Haskell starting") putStrLn ("TazBlog " ++ version ++ " in Haskell starting")
tbDir <- getEnv "TAZBLOG" runCommand $ \opts args ->
bracket (openLocalStateFrom (tbDir ++ "/BlogState") initialBlogState) bracket (openLocalStateFrom (optState opts ++ "BlogState") initialBlogState)
(createCheckpointAndClose) (createCheckpointAndClose)
(\acid -> simpleHTTP nullConf {port = 80} $ tazBlog acid) (\acid -> simpleHTTP nullConf {port = optPort opts} $ tazBlog acid)
tazBlog :: AcidState Blog -> ServerPart Response tazBlog :: AcidState Blog -> ServerPart Response
tazBlog acid = do tazBlog acid = do