module OptparseApplicative.Simple.Parser
(
Parser,
argument,
)
where
import BasePrelude
import Data.Text (Text)
import qualified Options.Applicative as A
import qualified Data.Attoparsec.Text as B
import qualified Data.Text as C
type Parser =
A.Parser
argument
:: Text
-> Maybe Char
-> Maybe Text
-> Maybe (a, Text)
-> B.Parser a
-> A.Parser a
argument longName shortName description defaultValue parser =
A.option readM mods
where
readM =
A.eitherReader (B.parseOnly parser . C.pack)
mods =
A.long (C.unpack longName) <>
foldMap A.short shortName <>
foldMap (A.help . C.unpack) description <>
foldMap (\(value, text) -> A.value value <> A.showDefaultWith (const (C.unpack text))) defaultValue