diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2011-02-03 14:18:09 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2011-02-03 14:18:09 +0100 |
commit | 5705bb8f88529b4170ffe884c668721abe9fccea (patch) | |
tree | 23934283815d7af1bb2db1622731d602dbde3041 | |
parent | 26c95402d8048f88c15aad273cca6a2829098d2a (diff) | |
download | hakyll-5705bb8f88529b4170ffe884c668721abe9fccea.tar.gz |
Add command-line args
-rw-r--r-- | src/Hakyll/Main.hs | 74 |
1 files changed, 72 insertions, 2 deletions
diff --git a/src/Hakyll/Main.hs b/src/Hakyll/Main.hs index 42b49ae..36a4010 100644 --- a/src/Hakyll/Main.hs +++ b/src/Hakyll/Main.hs @@ -5,17 +5,87 @@ module Hakyll.Main , hakyllWith ) where +import Control.Monad (when) +import System.Environment (getProgName, getArgs) +import System.Directory (doesDirectoryExist, removeDirectoryRecursive) + import Hakyll.Core.Configuration import Hakyll.Core.Run import Hakyll.Core.Rules +import Hakyll.Network.Server -- | This usualy is the function with which the user runs the hakyll compiler -- hakyll :: Rules -> IO () -hakyll = run defaultHakyllConfiguration +hakyll = hakyllWith defaultHakyllConfiguration -- | A variant of 'hakyll' which allows the user to specify a custom -- configuration -- hakyllWith :: HakyllConfiguration -> Rules -> IO () -hakyllWith = run +hakyllWith configuration rules = do + args <- getArgs + case args of + ["build"] -> build configuration rules + ["clean"] -> clean configuration + ["help"] -> help + ["preview"] -> putStrLn "Not implemented" + ["preview", p] -> putStrLn "Not implemented" + ["rebuild"] -> rebuild configuration rules + ["server"] -> server configuration 8000 + ["server", p] -> server configuration (read p) + _ -> help + +-- | Build the site +-- +build :: HakyllConfiguration -> Rules -> IO () +build = run + +-- | Remove the output directories +-- +clean :: HakyllConfiguration -> IO () +clean configuration = do + remove $ destinationDirectory configuration + remove $ storeDirectory configuration + where + remove dir = do + putStrLn $ "Removing " ++ dir ++ "..." + exists <- doesDirectoryExist dir + when exists $ removeDirectoryRecursive dir + +-- | Show usage information. +-- +help :: IO () +help = do + name <- getProgName + mapM_ putStrLn + [ "ABOUT" + , "" + , "This is a Hakyll site generator program. You should always" + , "run it from the project root directory." + , "" + , "USAGE" + , "" + , name ++ " build Generate the site" + , name ++ " clean Clean up and remove cache" + , name ++ " help Show this message" + , name ++ " preview [port] Run a server and autocompile" + , name ++ " rebuild Clean up and build again" + , name ++ " server [port] Run a local test server" + ] + +-- | Rebuild the site +-- +rebuild :: HakyllConfiguration -> Rules -> IO () +rebuild configuration rules = do + clean configuration + build configuration rules + +-- | Start a server +-- +server :: HakyllConfiguration -> Int -> IO () +server configuration port = do + let destination = destinationDirectory configuration + staticServer destination preServeHook port + where + preServeHook _ = return () |