summaryrefslogtreecommitdiff
path: root/lib/Language/Elna/CommandLine.hs
blob: b23be7dc3a25400c15be0841a3fb7d607cb7394c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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."