module Serokell.Util.OptParse
( fromStr
, strArgument
, strOption
, fromParsec
) where
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 String () a -> ReadM a
fromParsec parser = eitherReader $ either (Left . show) Right . parse parser "<CLI options>"