Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- parseIO :: ParserDetails -> Parser a -> IO a
- parseIOWithArgs :: ParserDetails -> Parser a -> [String] -> IO a
- pureParse :: ParserDetails -> Parser a -> [String] -> Maybe a
- testCLI :: Show a => ParserDetails -> Parser a -> [String] -> IO ()
- data ParserDetails = ParserDetails {
- _pd_desc :: String
- _pd_header :: String
- _pd_footer :: String
- mkParserInfo :: ParserDetails -> Parser a -> ParserInfo a
- type MetaVar = String
- type HelpText = String
- type FlagName = String
- type FlagChar = Char
- enumArgP :: forall a. EnumText a => MetaVar -> Parser a
- argP :: TextParsable a => MetaVar -> HelpText -> Parser a
- argP' :: (Text -> Either String a) -> MetaVar -> String -> Parser a
- enumOptP :: forall a. EnumText a => FlagChar -> MetaVar -> Parser a
- optP :: TextParsable a => FlagChar -> FlagName -> HelpText -> Parser a
- enumSwitchesP :: EnumText a => Parser a
- shortEnumSwitchesP :: forall a. EnumText a => (a -> Maybe FlagChar) -> Parser a
- module Text.Enum.Text
A simple Whole Example
A simple but complete example:
{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DerivingVia #-} {-# LANGUAGE OverloadedStrings #-} import Fmt import Text.Enum.Optparse import Paths_optparse_enum data Choice = C_version | C_hello deriving (Bounded,Enum,EnumText,Eq,Ord,Show) deriving (Buildable,TextParsable) via UsingEnumText Choice parserDetails :: ParserDetails parserDetails = ParserDetails { _pd_desc = "optparse-enum example program" , _pd_header = "A simple optparse-enum illustrative program" , _pd_footer = "See the optparse-enum page on Hackage for details" } main :: IO () main = do choice <- parseIO parserDetails enumSwitchesP case choice of C_version -> print version C_hello -> putStrLn "Hello!"
The Drivers
parseIOWithArgs :: ParserDetails -> Parser a -> [String] -> IO a Source #
making an IO parser, specifying the arguments
mkParserInfo
data ParserDetails Source #
ParserDetails | |
|
Instances
Show ParserDetails Source # | |
Defined in Text.Enum.Optparse showsPrec :: Int -> ParserDetails -> ShowS # show :: ParserDetails -> String # showList :: [ParserDetails] -> ShowS # |
mkParserInfo :: ParserDetails -> Parser a -> ParserInfo a Source #
given a Parser
makes up a corresponding ParserInfo
The Parser Generators
argP :: TextParsable a => MetaVar -> HelpText -> Parser a Source #
pasring a TextParsable
argument
argP' :: (Text -> Either String a) -> MetaVar -> String -> Parser a Source #
pasring an TextParsable
argument, the parser being passed explicitly
enumOptP :: forall a. EnumText a => FlagChar -> MetaVar -> Parser a Source #
parsing an EnumText
option
optP :: TextParsable a => FlagChar -> FlagName -> HelpText -> Parser a Source #
parsing a TextParsable
option
enumSwitchesP :: EnumText a => Parser a Source #
generate mutually exclusive switches based on EnumText
a
shortEnumSwitchesP :: forall a. EnumText a => (a -> Maybe FlagChar) -> Parser a Source #
generate mutually exclusive switches based on EnumText
a
, with
some short swich options as specified by the argument function
module Text.Enum.Text