This module implements a lightweight flags parser, inspired by
optparse-applicative.
Sample usage (note the default log level and optional context):
module Main where
import Control.Applicative ((<|>), optional)
import Data.Text (Text)
import Flags.Applicative
-- Custom flags for our example.
data Flags = Flags
{ rootPath :: Text
, logLevel :: Int
, context :: Maybe Text
} deriving Show
-- Returns a parser from CLI arguments to our custom flags.
flagsParser :: FlagsParser Flags
flagsParser = Flags
<$> flag textVal "root" "path to the root"
<*> (flag autoVal "log_level" "" <|> pure 0)
<*> (optional $ flag textVal "context" "")
main :: IO ()
main = do
(flags, args) <- parseSystemFlagsOrDie flagsParser
print flags