{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module MBug.Options (options, Options(..), showFolderMH) where
import Control.Applicative ((<**>))
import Data.Semigroup ((<>))
import Data.Text (Text)
import MBug.Data.FolderMH (FolderMH (..), readFolderMH, showFolderMH)
import Options.Applicative.Compat
( Parser
, execParser
, footer
, fullDesc
, header
, help
, helper
, info
, long
, maybeReader
, metavar
, option
, short
, showDefaultWith
, strArgument
, value
)
data Options = Options {
_folder :: FolderMH,
_query :: Text
}
folderParser :: Parser FolderMH
folderParser = option (maybeReader readFolderMH) mods
where
defaultFolderMH = Absolute "debbugs"
mods = short 'o'
<> long "into"
<> value defaultFolderMH
<> metavar "+folder"
<> showDefaultWith showFolderMH
<> help "MH folder to store bug emails"
queryParser :: Parser Text
queryParser = strArgument mods
where
mods = metavar "QUERY"
<> help "Query to Debian bug system"
optionsParser :: Parser Options
optionsParser = Options <$> folderParser <*> queryParser
options :: IO Options
options = execParser $ info (optionsParser <**> helper) mods
where
mods = fullDesc
<> header "Download Debian bugs into MH folder"
<> footer "Copyright (C) 2018 Dmitry Bogatov <KAction@gnu.org>"