Browse files

DB path is command line param

  • Loading branch information...
1 parent d6ad239 commit 9d464d97045d8f10a1670d7226204c96d60b4d6e @singpolyma committed Mar 23, 2013
Showing with 10 additions and 6 deletions.
  1. +2 −1 .gitignore
  2. +8 −5 Main.hs
View
3 .gitignore
@@ -7,7 +7,8 @@ Main
MustacheTemplates.hs
PathHelpers.hs
Routes.hs
-dev.db
+*.db
+*.sqlite3
tests/suite
dist/*
report.html
View
13 Main.hs
@@ -4,7 +4,7 @@ import Prelude hiding (FilePath)
import Control.Monad (void)
import System.Environment (getArgs)
import Network.URI (parseAbsoluteURI, URI(..))
-import Control.Error (err)
+import Control.Error (err, headMay)
import Filesystem.Path (FilePath)
import Filesystem (getWorkingDirectory)
@@ -31,12 +31,15 @@ staticRoot :: FilePath -> Application
staticRoot = staticApp . defaultWebAppSettings
main :: IO ()
-main = main' . map (fmap addTrailingSlash . parseAbsoluteURI) =<< getArgs
+main = do
+ args <- getArgs
+ let root = fmap addTrailingSlash (parseAbsoluteURI =<< headMay args)
+ main' root args
where
- main' [Just root@(URI {uriAuthority = Just _})] = do
+ main' (Just root@(URI {uriAuthority = Just _})) (_:dbpth:_) = do
cwd <- getWorkingDirectory
- void $ withConnection "./dev.db"
+ void $ withConnection dbpth
(\db -> run 3000 $
logStdoutDev $ autohead $ acceptOverride $ jsonp $ -- Middleware
dispatch (staticRoot cwd) $ routes root db) -- Do routing
- main' _ = err "Usage: ./Main <Root URI>"
+ main' _ _ = err "Usage: ./Main <Root URI> <DB path>"

0 comments on commit 9d464d9

Please sign in to comment.