From 45df822904cd1759ea4be4bf0c125d8fb6542479 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 27 Dec 2019 14:44:07 +0100 Subject: compiler: switch to cmdargs --- compiler/app/Main.hs | 60 +++++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 34 deletions(-) (limited to 'compiler/app') diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index d9b019a..1773073 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs @@ -17,50 +17,42 @@ -- along with this program. If not, see . {-# LANGUAGE - RecordWildCards - , ApplicativeDo + DeriveDataTypeable #-} module Main where -import Options.Applicative -import Data.Semigroup ((<>)) +import Paths_ldgallery_compiler (version) +import Data.Version (showVersion) +import System.Console.CmdArgs import Compiler -data Args = Args + +data Options = Options { inputDir :: String , outputDir :: String - , rebuild :: Bool } + , rebuild :: Bool + } deriving (Show, Data, Typeable) + +options = Options + { inputDir = "./" + &= typDir + &= help "Gallery source directory (default=./)" + , outputDir = "./out" + &= typDir + &= help "Generated gallery output path (default=./out)" + , rebuild = False + &= help "Invalidate cache and recompile everything" + } + &= summary ("ldgallery v" ++ (showVersion version) ++ " - a static gallery generator with tags") + &= program "ldgallery" + &= help "Compile a gallery" + &= helpArg [explicit, name "h", name "help"] + &= versionArg [explicit, name "v", name "version"] -args :: Parser Args -args = Args - <$> strOption - ( long "input" - <> short 'i' - <> metavar "SOURCE DIR" - <> value "./" - <> showDefault - <> help "Gallery source directory" ) - <*> strOption - ( long "output" - <> short 'o' - <> metavar "OUTPUT DIR" - <> value "./out" - <> showDefault - <> help "Generated gallery output path" ) - <*> switch - ( long "rebuild" - <> short 'r' - <> help "Invalidate cache and recompile everything" ) main :: IO () main = do - options <- execParser opts - compileGallery (inputDir options) (outputDir options) (rebuild options) - - where - opts = info (args <**> helper) - ( fullDesc - <> progDesc "Compile a gallery" - <> header "ldgallery - a static gallery generator with tags" ) + opts <- cmdArgs options + compileGallery (inputDir opts) (outputDir opts) (rebuild opts) -- cgit v1.2.3