summaryrefslogtreecommitdiff
path: root/lib/Language/Elna/CommandLine.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2024-09-05 23:18:48 +0200
committerEugen Wissner <belka@caraus.de>2024-09-05 23:18:48 +0200
commit042e4e8714263fe0568e1e382232dae56afa2ed1 (patch)
treef7c0b9d68a44565fac4903bf7447fdf20628c4b8 /lib/Language/Elna/CommandLine.hs
parentbe73032b939486c6207b441fb7bdfb0bda172b5d (diff)
downloadelna-042e4e8714263fe0568e1e382232dae56afa2ed1.tar.gz
Add command line parser
Diffstat (limited to 'lib/Language/Elna/CommandLine.hs')
-rw-r--r--lib/Language/Elna/CommandLine.hs44
1 files changed, 44 insertions, 0 deletions
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."