Commit e9af2c6322ba0d4801c60cfee4127344942a174c Parent: 7202b63e679970f0ae1ce39730c4d22751fdc7af Author: mcol <mcol@posteo.net> Date: 2021-11-20 21:18:19 +0000 Committer: mcol <mcol@posteo.net> Committed: 2021-11-20 21:18:19 +0000 Add command line arg parsing
src/Templates.hs Modified
@@ -45,6 +45,7 @@ , envIndexTemplate :: Maybe Template , envCommitTemplate :: Maybe Template , envFileTemplate :: Maybe Template + , envForce :: Bool } data Template = Template @@ -56,8 +57,8 @@ This creates the runtime environment, collecting the config and loading template data from file. -} -loadTemplates :: Config -> IO Env -loadTemplates config = do +loadTemplates :: Bool -> Config -> IO Env +loadTemplates force config = do -- Custom templates files <- getFiles config templates <- mapM loadTemplate files @@ -71,6 +72,7 @@ , envIndexTemplate = indexT , envCommitTemplate = commitT , envFileTemplate = fileT + , envForce = force } {-
src/Main.hs Modified
@@ -4,13 +4,62 @@ main ) where +import Data.Text (Text) +import qualified Options.Applicative as O + import Config (getConfig) import Index (runIndex) import Templates (loadTemplates) import Repositories (run) +{- +Command line options +-} +data Options = Options + { config :: Text + , force :: Bool + , version :: Bool + } + +opts :: O.Parser Options +opts = Options + <$> O.strOption ( + O.long "config" <> + O.short 'c' <> + O.metavar "CONFIG" <> + O.value "./config.dhall" <> + O.help "Configuration file to use (Default: ./config.dhall)" + ) + <*> O.switch ( + O.long "force" <> + O.short 'f' <> + O.help "Force regeneration of all files" + ) + <*> O.switch ( + O.long "version" <> + O.short 'v' <> + O.help "Print the gitserve's version" + ) + +parser :: IO Options +parser = O.execParser $ O.info (opts O.<**> O.helper) + ( O.progDesc "🐙 Templated web page generator for your git repositories" + ) + +{- +Main logic +-} main :: IO () main = do - env <- loadTemplates =<< getConfig "./config.dhall" - runIndex env - run env + options <- parser + if (version options) + then + putStrLn $ "Your gitserve version is: " <> currentVersion + else do + conf <- getConfig (config options) + env <- loadTemplates (force options) conf + runIndex env + run env + +currentVersion :: String +currentVersion = "0.0.0"
gitserve.cabal Modified
@@ -27,6 +27,7 @@ , ginger >= 0.10.3 , gitlib , gitlib-libgit2 + , optparse-applicative , tagged , text , transformers
README.rst Modified
@@ -31,7 +31,6 @@ - Commit diffs - Write guide -- Specify config on the command line - Improve performance Meta