about summary refs log tree commit diff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@googlemail.com>2012-03-25T17·29+0200
committerVincent Ambo <tazjin@googlemail.com>2012-03-25T17·29+0200
commit8b64d14a72b5f17cc27c22099ec912cb953988a4 (patch)
treed8652143c8982b9cb97be231201e4cbb2c18fb92 /src/Main.hs
parent74ce7d9bf0c837b89c48579b6c97dac3ce042093 (diff)
* removed System.Environment from Main.hs
* using the brand-new Options package to parse command line options (--port and --statedir)
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/Main.hs b/src/Main.hs
index bf8b52b49b76..06bf4d3f63e4 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -24,7 +24,7 @@ import           Data.Time
 import           Data.SafeCopy (base, deriveSafeCopy)
 import           Happstack.Server hiding (Session)
 import           Happstack.Server.Compression
-import           System.Environment(getEnv)
+import           Options
 import           System.Locale (defaultTimeLocale)
 
 import           Blog
@@ -34,16 +34,23 @@ import           RSS
 
 {- 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 = (defaultBodyPolicy "./tmp/" 0 200000 1000)
 
 main :: IO()
 main = do
     putStrLn ("TazBlog " ++ version ++ " in Haskell starting")
-    tbDir <- getEnv "TAZBLOG"
-    bracket (openLocalStateFrom (tbDir ++ "/BlogState") initialBlogState)
-            (createCheckpointAndClose)
-            (\acid -> simpleHTTP nullConf {port = 80} $ tazBlog acid)
+    runCommand $ \opts args ->
+      bracket (openLocalStateFrom (optState opts ++ "BlogState") initialBlogState)
+              (createCheckpointAndClose)
+              (\acid -> simpleHTTP nullConf {port = optPort opts} $ tazBlog acid)
 
 tazBlog :: AcidState Blog -> ServerPart Response
 tazBlog acid = do