module Serokell.Util.OptParse
( fromStr
, strArgument
, strOption
, fromParsec
) where
import Universum
import Data.String (IsString (fromString))
import Options.Applicative (ArgumentFields, Mod, OptionFields, Parser, ReadM,
argument, eitherReader, option, str)
import Text.Parsec (Parsec, parse)
fromStr :: IsString s => ReadM s
fromStr = fromString <$> str
strArgument :: IsString s => Mod ArgumentFields s -> Parser s
strArgument = argument fromStr
strOption :: IsString s => Mod OptionFields s -> Parser s
strOption = option fromStr
fromParsec :: Parsec Text () a -> ReadM a
fromParsec parser =
eitherReader $ first show . parse parser "<CLI options>" . toText