From 042e4e8714263fe0568e1e382232dae56afa2ed1 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Thu, 5 Sep 2024 23:18:48 +0200 Subject: Add command line parser --- lib/Language/Elna/CommandLine.hs | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 lib/Language/Elna/CommandLine.hs (limited to 'lib/Language/Elna/CommandLine.hs') diff --git a/lib/Language/Elna/CommandLine.hs b/lib/Language/Elna/CommandLine.hs new file mode 100644 index 0000000..b23be7d --- /dev/null +++ b/lib/Language/Elna/CommandLine.hs @@ -0,0 +1,44 @@ +module Language.Elna.CommandLine + ( CommandLine(..) + , commandLine + , execParser + ) where + +import Options.Applicative + ( Parser + , ParserInfo(..) + , argument + , execParser + , fullDesc + , help + , helper + , info + , long + , metavar + , optional + , progDesc + , short + , str + , strOption + ) +import Control.Applicative ((<**>)) + +data CommandLine = CommandLine + { input :: FilePath + , output :: Maybe FilePath + } deriving (Eq, Show) + +parser :: Parser CommandLine +parser = CommandLine + <$> argument str inFile + <*> optional (strOption outFile) + where + inFile = metavar "INFILE" <> help "Input file." + outFile = long "output" + <> short 'o' + <> metavar "OUTFILE" + <> help "Output file." + +commandLine :: ParserInfo CommandLine +commandLine = info (parser <**> helper) + $ fullDesc <> progDesc "Elna compiler." -- cgit v1.2.3