on master help sign in
Import Options.Applicative qualified
commit85d9ccd1552987caf9c81c05eda02c399b14dc5b authorJasper Van der Jeugt <m@jaspervdj.be> dateSat 10 Jun 2017, 17:22 (9 years ago) parent40945cd
1 file changed+55−28
src/Hakyll/Main.hs+55−28
src/Hakyll/Main.hs+55−28
@@ -1,6 +1,6 @@
11--------------------------------------------------------------------------------
22-- | Module providing the main hakyll function and command-line argument parsing
3−{-# LANGUAGE CPP #-}
3+{-# LANGUAGE CPP #-}
44
55module Hakyll.Main
66 ( hakyll
@@ -11,20 +11,21 @@ module Hakyll.Main
1111
1212
1313--------------------------------------------------------------------------------
14−import System.Environment (getProgName)
15−import System.IO.Unsafe (unsafePerformIO)
16−import System.Exit (ExitCode(ExitSuccess), exitWith)
14+import System.Environment (getProgName)
15+import System.Exit (ExitCode (ExitSuccess), exitWith)
16+import System.IO.Unsafe (unsafePerformIO)
1717
1818
1919--------------------------------------------------------------------------------
20−import Options.Applicative
20+import Data.Monoid ((<>))
21+import qualified Options.Applicative as OA
2122
2223
2324--------------------------------------------------------------------------------
24−import qualified Hakyll.Check as Check
25−import qualified Hakyll.Commands as Commands
26−import qualified Hakyll.Core.Configuration as Config
27−import qualified Hakyll.Core.Logger as Logger
25+import qualified Hakyll.Check as Check
26+import qualified Hakyll.Commands as Commands
27+import qualified Hakyll.Core.Configuration as Config
28+import qualified Hakyll.Core.Logger as Logger
2829import Hakyll.Core.Rules
2930
3031
@@ -68,9 +69,9 @@ hakyllWithExitCodeAndArgs conf args rules = do
6869--------------------------------------------------------------------------------
6970defaultParser :: Config.Configuration -> IO Options
7071defaultParser conf =
71− customExecParser (prefs showHelpOnError)
72− (info (helper <*> optionParser conf)
73− (fullDesc <> progDesc
72+ OA.customExecParser (OA.prefs OA.showHelpOnError)
73+ (OA.info (OA.helper <*> optionParser conf)
74+ (OA.fullDesc <> OA.progDesc
7475 (progName ++ " - Static site compiler created with Hakyll")))
7576
7677
@@ -107,27 +108,53 @@ data Command
107108 | Watch {host :: String, port :: Int, no_server :: Bool }
108109 deriving (Show)
109110
110−optionParser :: Config.Configuration -> Parser Options
111+optionParser :: Config.Configuration -> OA.Parser Options
111112optionParser conf = Options <$> verboseParser <*> commandParser conf
112113 where
113− verboseParser = switch (long "verbose" <> short 'v' <> help "Run in verbose mode")
114+ verboseParser = OA.switch (OA.long "verbose" <> OA.short 'v' <> OA.help "Run in verbose mode")
114115
115116
116−commandParser :: Config.Configuration -> Parser Command
117−commandParser conf = subparser $ foldr ((<>) . produceCommand) mempty commands
117+commandParser :: Config.Configuration -> OA.Parser Command
118+commandParser conf = OA.subparser $ foldr ((<>) . produceCommand) mempty commands
118119 where
119− produceCommand (a,b) = command a (info (helper <*> fst b) (snd b))
120− portParser = option auto (long "port" <> help "Port to listen on" <> value (Config.previewPort conf))
121− hostParser = strOption (long "host" <> help "Host to bind on" <> value (Config.previewHost conf))
122− commands = [
123− ("build", (pure Build,fullDesc <> progDesc "Generate the site")),
124− ("check", (pure Check <*> switch (long "internal-links" <> help "Check internal links only"), fullDesc <> progDesc "Validate the site output")),
125− ("clean", (pure Clean,fullDesc <> progDesc "Clean up and remove cache")),
126− ("deploy", (pure Deploy,fullDesc <> progDesc "Upload/deploy your site")),
127− ("preview", (pure Preview <*> portParser,fullDesc <> progDesc "[DEPRECATED] Please use the watch command")),
128− ("rebuild", (pure Rebuild,fullDesc <> progDesc "Clean and build again")),
129− ("server", (pure Server <*> hostParser <*> portParser,fullDesc <> progDesc "Start a preview server")),
130− ("watch", (pure Watch <*> hostParser <*> portParser <*> switch (long "no-server" <> help "Disable the built-in web server"),fullDesc <> progDesc "Autocompile on changes and start a preview server. You can watch and recompile without running a server with --no-server."))
120+ portParser = OA.option OA.auto (OA.long "port" <> OA.help "Port to listen on" <> OA.value (Config.previewPort conf))
121+ hostParser = OA.strOption (OA.long "host" <> OA.help "Host to bind on" <> OA.value (Config.previewHost conf))
122+
123+ produceCommand (c,a,b) = OA.command c (OA.info (OA.helper <*> a) (b))
124+
125+ commands =
126+ [ ( "build"
127+ , pure Build
128+ , OA.fullDesc <> OA.progDesc "Generate the site"
129+ )
130+ , ( "check"
131+ , pure Check <*> OA.switch (OA.long "internal-links" <> OA.help "Check internal links only")
132+ , OA.fullDesc <> OA.progDesc "Validate the site output"
133+ )
134+ , ( "clean"
135+ , pure Clean
136+ , OA.fullDesc <> OA.progDesc "Clean up and remove cache"
137+ )
138+ , ( "deploy"
139+ , pure Deploy
140+ , OA.fullDesc <> OA.progDesc "Upload/deploy your site"
141+ )
142+ , ( "preview"
143+ , pure Preview <*> portParser
144+ , OA.fullDesc <> OA.progDesc "[DEPRECATED] Please use the watch command"
145+ )
146+ , ( "rebuild"
147+ , pure Rebuild
148+ , OA.fullDesc <> OA.progDesc "Clean and build again"
149+ )
150+ , ( "server"
151+ , pure Server <*> hostParser <*> portParser
152+ , OA.fullDesc <> OA.progDesc "Start a preview server"
153+ )
154+ , ( "watch"
155+ , pure Watch <*> hostParser <*> portParser <*> OA.switch (OA.long "no-server" <> OA.help "Disable the built-in web server")
156+ , OA.fullDesc <> OA.progDesc "Autocompile on changes and start a preview server. You can watch and recompile without running a server with --no-server."
157+ )
131158 ]
132159
133160