module Trial.OptparseApplicative
( trialParser
, taggedTrialParser
, trialOption
, taggedTrialOption
) where
import Data.String (IsString (..))
import Options.Applicative (Parser, ReadM, long, option, optional)
import Trial (TaggedTrial, Trial, maybeToTrial, withTag)
trialParser
:: (Semigroup e, IsString e)
=> String
-> Parser a
-> Parser (Trial e a)
trialParser field parser = mToTrial field <$> optional parser
taggedTrialParser
:: (Semigroup e, IsString e)
=> String
-> Parser a
-> Parser (TaggedTrial e a)
taggedTrialParser field parser = mToTaggedTrial field <$> optional parser
trialOption
:: (Semigroup e, IsString e)
=> String
-> ReadM a
-> Parser (Trial e a)
trialOption field opt = mToTrial field <$>
optional (option opt (long field))
taggedTrialOption
:: (Semigroup e, IsString e)
=> String
-> ReadM a
-> Parser (TaggedTrial e a)
taggedTrialOption field opt = mToTaggedTrial field <$>
optional (option opt (long field))
mToTaggedTrial :: (Semigroup e, IsString e) => String -> Maybe a -> TaggedTrial e a
mToTaggedTrial field = withTag "CLI" . mToTrial field
mToTrial :: (Semigroup e, IsString e) => String -> Maybe a -> Trial e a
mToTrial field = maybeToTrial ("No CLI option specified for " <> fromString field)