1--------------------------------------------------------------------------------
2-- | Module providing the main hakyll function and command-line argument parsing
4{-# LANGUAGE DeriveDataTypeable #-}
11--------------------------------------------------------------------------------
12import System.Console.CmdArgs
13import qualified System.Console.CmdArgs.Explicit as CA
14import System.Environment (getProgName)
15import System.IO.Unsafe (unsafePerformIO)
18--------------------------------------------------------------------------------
19import qualified Hakyll.Check as Check
20import qualified Hakyll.Commands as Commands
21import qualified Hakyll.Core.Configuration as Config
22import qualified Hakyll.Core.Logger as Logger
23import Hakyll.Core.Rules
26--------------------------------------------------------------------------------
27-- | This usualy is the function with which the user runs the hakyll compiler
28hakyll :: Rules a -> IO ()
29hakyll = hakyllWith Config.defaultConfiguration
32--------------------------------------------------------------------------------
33-- | A variant of 'hakyll' which allows the user to specify a custom
35hakyllWith :: Config.Configuration -> Rules a -> IO ()
36hakyllWith conf rules = do
37 args' <- cmdArgs hakyllArgs
39 let verbosity' = if verbose args' then Logger.Debug else Logger.Message
41 if internal_links args' then Check.InternalLinks else Check.All
44 Build _ -> Commands.build conf verbosity' rules
45 Check _ _ -> Commands.check conf verbosity' check'
46 Clean _ -> Commands.clean conf
47 Deploy _ -> Commands.deploy conf
49 Preview _ p -> Commands.preview conf verbosity' rules p
50 Rebuild _ -> Commands.rebuild conf verbosity' rules
51 Server _ _ -> Commands.server conf (port args')
54--------------------------------------------------------------------------------
55-- | Show usage information.
57showHelp = print $ CA.helpText [] CA.HelpFormatOne $ cmdArgsMode hakyllArgs
60--------------------------------------------------------------------------------
62 = Build {verbose :: Bool}
63 | Check {verbose :: Bool, internal_links :: Bool}
64 | Clean {verbose :: Bool}
65 | Deploy {verbose :: Bool}
66 | Help {verbose :: Bool}
67 | Preview {verbose :: Bool, port :: Int}
68 | Rebuild {verbose :: Bool}
69 | Server {verbose :: Bool, port :: Int}
70 deriving (Data, Typeable, Show)
73--------------------------------------------------------------------------------
74hakyllArgs :: HakyllArgs
76 [ (Build $ verboseFlag def) &= help "Generate the site"
77 , (Check (verboseFlag def) (False &= help "Check internal links only")) &=
78 help "Validate the site output"
79 , (Clean $ verboseFlag def) &= help "Clean up and remove cache"
80 , (Deploy $ verboseFlag def) &= help "Upload/deploy your site"
81 , (Help $ verboseFlag def) &= help "Show this message" &= auto
82 , (Preview (verboseFlag def) (portFlag 8000)) &=
83 help "Start a preview server and autocompile on changes"
84 , (Rebuild $ verboseFlag def) &= help "Clean and build again"
85 , (Server (verboseFlag def) (portFlag 8000)) &=
86 help "Start a preview server"
87 ] &= help "Hakyll static site compiler" &= program progName
90--------------------------------------------------------------------------------
91verboseFlag :: Data a => a -> a
92verboseFlag x = x &= help "Run in verbose mode"
93{-# INLINE verboseFlag #-}
96--------------------------------------------------------------------------------
97portFlag :: Data a => a -> a
98portFlag x = x &= help "Port to listen on"
99{-# INLINE portFlag #-}
102--------------------------------------------------------------------------------
103-- | This is necessary because not everyone calls their program the same...
105progName = unsafePerformIO getProgName
106{-# NOINLINE progName #-}
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list