From c6d86aeed3491f88bbfdf9667882a49efc509b1d Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Thu, 8 Jun 2023 14:25:32 +0200 Subject: actually take args --- Types.hs | 79 +++++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 61 insertions(+), 18 deletions(-) (limited to 'Types.hs') diff --git a/Types.hs b/Types.hs index 8e53611..e818c63 100644 --- a/Types.hs +++ b/Types.hs @@ -1,4 +1,6 @@ {-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE ApplicativeDo #-} +{-# LANGUAGE RecordWildCards #-} -- | Separated-out main types of the deployment scriptage. module Types where @@ -8,6 +10,7 @@ import qualified Data.Map as M import qualified Data.Set as S import qualified Data.Yaml as Y import Lens.Micro.TH +import Options.Applicative import qualified Text.Mustache as Mu import qualified Text.Pandoc.Definition @@ -51,23 +54,63 @@ data SiteState = makeLenses ''SiteState --- | Make a completely empty `SiteState` for the `Site` monad. -emptySiteState = - SiteState - { _pages = M.empty - , _redirects = M.empty - , _htags = M.empty - , _installs = S.empty - , _targets = S.empty - , _templates = M.empty - , _outputDir = "_site" - , _assetDir = "assets" - , _defaultTemplate = "default.html" - , _redirectTemplate = "redirect.html" - , _tagTemplate = "tag.html" - , _urlBase = "/" - , _dumpFinalState = False - } - -- | Monad for running the site generator. type Site a = StateT SiteState IO a + +-- | Parser for commandline options +siteOptions' :: Parser SiteState +siteOptions' = do + _outputDir <- + strOption $ + long "output" <> + short 'd' <> + help "Directory to render the site to" <> value "_site" <> showDefault + _assetDir <- + strOption $ + long "assets" <> + short 'a' <> + help "Assets directory to be copied verbatim" <> + value "assets" <> showDefault + --TODO templates directory! + _defaultTemplate <- + strOption $ + long "default-template" <> + help "Default template to use for stuff (found in templates directory)" <> + value "default.html" <> showDefault + _redirectTemplate <- + strOption $ + long "redirect-template" <> + help "Template for making redirect pages" <> + value "redirect.html" <> showDefault + _tagTemplate <- + strOption $ + long "tag-template" <> + help "Template for making tag-listing pages" <> + value "tag.html" <> showDefault + _urlBase <- + strOption $ + long "url-base" <> + short 'u' <> help "Base absolute URL" <> value "/" <> showDefault + _dumpFinalState <- + switch $ + long "dump-state" <> + short 'D' <> + help "Print out the complete internal state after the site is built" + pure + SiteState + { _pages = M.empty + , _redirects = M.empty + , _htags = M.empty + , _installs = S.empty + , _targets = S.empty + , _templates = M.empty + , .. + } + +-- | ParserInfo for commandline options +siteOptions = + info + (siteOptions' <**> helper) + (fullDesc <> + progDesc "Build a R3 Cards-like site" <> + header "site - the R3 site builder") -- cgit v1.2.3