Copyright | Copyright © 2015 PivotCloud Inc. |
---|---|
License | MIT |
Maintainer | Lars Kuhtz <lkuhtz@pivotmail.com> |
Stability | experimental |
Safe Haskell | Safe |
Language | Haskell2010 |
This module provides tools for defining command line parsers for configuration types.
Unlike normal command line parsers the parsers for configuration types are expected to yield an update function that takes a value and updates the value with the settings from the command line.
Assuming that
- all configuration types are nested Haskell records or simple types and
- that there are lenses for all record fields
usually the operators .::
and %::
are all that is needed from this module.
The module Configuration.Utils.Monoid provides tools for the case that
a simple type is a container with a monoid instance, such as List
or
HashMap
.
The module Configuration.Utils.Maybe explains the usage of optional
Maybe
values in configuration types.
Synopsis
- type MParser a = Parser (a -> a)
- (.::) :: (Alternative f, Applicative f) => Lens' a b -> f b -> f (a -> a)
- (%::) :: (Alternative f, Applicative f) => Lens' a b -> f (b -> b) -> f (a -> a)
- boolReader :: (Eq a, Show a, FoldCase a, IsString a, IsString e, Monoid e) => a -> Either e Bool
- boolOption :: Mod OptionFields Bool -> Parser Bool
- boolOption_ :: Mod FlagFields Bool -> Parser Bool
- enableDisableFlag :: Mod FlagFields Bool -> Parser Bool
- fileOption :: Mod OptionFields String -> Parser FilePath
- eitherReadP :: Text -> ReadP a -> Text -> Either Text a
- (<$) :: Functor f => a -> f b -> f a
- class Functor f => Applicative (f :: * -> *) where
- mappend :: Monoid a => a -> a -> a
- class Applicative f => Alternative (f :: * -> *) where
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- optional :: Alternative f => f a -> f (Maybe a)
- newtype WrappedMonad (m :: * -> *) a = WrapMonad {
- unwrapMonad :: m a
- newtype WrappedArrow (a :: * -> * -> *) b c = WrapArrow {
- unwrapArrow :: a b c
- newtype ZipList a = ZipList {
- getZipList :: [a]
- newtype Const a (b :: k) :: forall k. * -> k -> * = Const {
- getConst :: a
- liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
- liftA :: Applicative f => (a -> b) -> f a -> f b
- (<**>) :: Applicative f => f a -> f (a -> b) -> f b
- renderFailure :: ParserFailure ParserHelp -> String -> (String, ExitCode)
- parserFailure :: ParserPrefs -> ParserInfo a -> ParseError -> [Context] -> ParserFailure ParserHelp
- execParserPure :: ParserPrefs -> ParserInfo a -> [String] -> ParserResult a
- getParseResult :: ParserResult a -> Maybe a
- handleParseResult :: ParserResult a -> IO a
- customExecParser :: ParserPrefs -> ParserInfo a -> IO a
- execParser :: ParserInfo a -> IO a
- hsubparser :: Mod CommandFields a -> Parser a
- helper :: Parser (a -> a)
- defaultPrefs :: ParserPrefs
- idm :: Monoid m => m
- prefs :: PrefsMod -> ParserPrefs
- columns :: Int -> PrefsMod
- noBacktrack :: PrefsMod
- showHelpOnEmpty :: PrefsMod
- showHelpOnError :: PrefsMod
- disambiguate :: PrefsMod
- multiSuffix :: String -> PrefsMod
- info :: Parser a -> InfoMod a -> ParserInfo a
- forwardOptions :: InfoMod a
- noIntersperse :: InfoMod a
- failureCode :: Int -> InfoMod a
- progDescDoc :: Maybe Doc -> InfoMod a
- progDesc :: String -> InfoMod a
- footerDoc :: Maybe Doc -> InfoMod a
- footer :: String -> InfoMod a
- headerDoc :: Maybe Doc -> InfoMod a
- header :: String -> InfoMod a
- briefDesc :: InfoMod a
- fullDesc :: InfoMod a
- option :: ReadM a -> Mod OptionFields a -> Parser a
- strOption :: IsString s => Mod OptionFields s -> Parser s
- infoOption :: String -> Mod OptionFields (a -> a) -> Parser (a -> a)
- abortOption :: ParseError -> Mod OptionFields (a -> a) -> Parser (a -> a)
- switch :: Mod FlagFields Bool -> Parser Bool
- flag' :: a -> Mod FlagFields a -> Parser a
- flag :: a -> a -> Mod FlagFields a -> Parser a
- strArgument :: IsString s => Mod ArgumentFields s -> Parser s
- argument :: ReadM a -> Mod ArgumentFields a -> Parser a
- subparser :: Mod CommandFields a -> Parser a
- completer :: HasCompleter f => Completer -> Mod f a
- action :: HasCompleter f => String -> Mod f a
- completeWith :: HasCompleter f => [String] -> Mod f a
- commandGroup :: String -> Mod CommandFields a
- command :: String -> ParserInfo a -> Mod CommandFields a
- style :: (Doc -> Doc) -> Mod f a
- hidden :: Mod f a
- metavar :: HasMetavar f => String -> Mod f a
- noArgError :: ParseError -> Mod OptionFields a
- helpDoc :: Maybe Doc -> Mod f a
- help :: String -> Mod f a
- showDefault :: Show a => Mod f a
- showDefaultWith :: (a -> String) -> Mod f a
- value :: HasValue f => a -> Mod f a
- long :: HasName f => String -> Mod f a
- short :: HasName f => Char -> Mod f a
- disabled :: ReadM a
- maybeReader :: (String -> Maybe a) -> ReadM a
- eitherReader :: (String -> Either String a) -> ReadM a
- str :: IsString s => ReadM s
- auto :: Read a => ReadM a
- data InfoMod a
- data PrefsMod
- bashCompleter :: String -> Completer
- listCompleter :: [String] -> Completer
- listIOCompleter :: IO [String] -> Completer
- internal :: Mod f a
- data OptionFields a
- data FlagFields a
- data CommandFields a
- data ArgumentFields a
- class HasName (f :: * -> *)
- class HasCompleter (f :: * -> *)
- class HasValue (f :: * -> *)
- class HasMetavar (f :: * -> *)
- data Mod (f :: * -> *) a
- overFailure :: (ParserHelp -> ParserHelp) -> ParserResult a -> ParserResult a
- mkCompleter :: (String -> IO [String]) -> Completer
- readerError :: String -> ReadM a
- readerAbort :: ParseError -> ReadM a
- data ParseError
- data ParserInfo a = ParserInfo {
- infoParser :: Parser a
- infoFullDesc :: Bool
- infoProgDesc :: Chunk Doc
- infoHeader :: Chunk Doc
- infoFooter :: Chunk Doc
- infoFailureCode :: Int
- infoPolicy :: ArgPolicy
- data ParserPrefs = ParserPrefs {}
- data ReadM a
- data Completer
- newtype CompletionResult = CompletionResult {
- execCompletion :: String -> IO String
- newtype ParserFailure h = ParserFailure {
- execFailure :: String -> (h, ExitCode, Int)
- data ParserResult a
- data ParserHelp = ParserHelp {}
Documentation
(.::) :: (Alternative f, Applicative f) => Lens' a b -> f b -> f (a -> a) infixr 5 Source #
An operator for applying a setter to an option parser that yields a value.
Example usage:
data Auth = Auth { _user ∷ !String , _pwd ∷ !String } user ∷ Functor f ⇒ (String → f String) → Auth → f Auth user f s = (\u → s { _user = u }) <$> f (_user s) pwd ∷ Functor f ⇒ (String → f String) → Auth → f Auth pwd f s = (\p → s { _pwd = p }) <$> f (_pwd s) -- or with lenses and TemplateHaskell just: -- $(makeLenses ''Auth) pAuth ∷ MParser Auth pAuth = id <$< user .:: strOption × long "user" ⊕ short 'u' ⊕ help "user name" <*< pwd .:: strOption × long "pwd" ⊕ help "password for user"
(%::) :: (Alternative f, Applicative f) => Lens' a b -> f (b -> b) -> f (a -> a) infixr 5 Source #
An operator for applying a setter to an option parser that yields a modification function.
Example usage:
data HttpURL = HttpURL { _auth ∷ !Auth , _domain ∷ !String } auth ∷ Functor f ⇒ (Auth → f Auth) → HttpURL → f HttpURL auth f s = (\u → s { _auth = u }) <$> f (_auth s) domain ∷ Functor f ⇒ (String → f String) → HttpURL → f HttpURL domain f s = (\u → s { _domain = u }) <$> f (_domain s) path ∷ Functor f ⇒ (String → f String) → HttpURL → f HttpURL path f s = (\u → s { _path = u }) <$> f (_path s) -- or with lenses and TemplateHaskell just: -- $(makeLenses ''HttpURL) pHttpURL ∷ MParser HttpURL pHttpURL = id <$< auth %:: pAuth <*< domain .:: strOption × long "domain" ⊕ short 'd' ⊕ help "HTTP domain"
Misc Utils
boolReader :: (Eq a, Show a, FoldCase a, IsString a, IsString e, Monoid e) => a -> Either e Bool Source #
boolOption :: Mod OptionFields Bool -> Parser Bool Source #
The boolOption
is an alternative to switch
.
Using switch
with command line parsers that overwrite settings
from a configuration file is problematic: the absence of the switch
is interpreted as setting the respective configuration value to False
.
So there is no way to specify on the command line that the value from
the configuration file shall be used. Some command line UIs use two
different options for those values, for instance --enable-feature
and
--disable-feature
. This option instead expects a Boolean value. Beside
that it behaves like any other option.
boolOption_ :: Mod FlagFields Bool -> Parser Bool Source #
An alternative syntax for boolOption
for options with long names.
Instead of taking a boolean argument the presence of the option acts as a
switch to set the respective configuration setting to True
. If the option
is not present the setting is left unchanged.
In addition for long option names a respective unset flag is provided. For
instance for a flag --verbose
there will also be a flag --no-verbose
.
This can still be used with short option names only, but no unset flag would be provided.
enableDisableFlag :: Mod FlagFields Bool -> Parser Bool Source #
An option parser for flags that are enabled via the flag name prefixed
with --enable-
and disabled via the flag name prefix --disable-
. The
prefixes are applied to all long option names. Short option names are parsed
unchanged and and cause the flag to be enabled.
This resembles the style of flags that is used for instances with Cabal.
fileOption :: Mod OptionFields String -> Parser FilePath Source #
class Functor f => Applicative (f :: * -> *) where #
A functor with application, providing operations to
A minimal complete definition must include implementations of pure
and of either <*>
or liftA2
. If it defines both, then they must behave
the same as their default definitions:
(<*>
) =liftA2
id
liftA2
f x y = f<$>
x<*>
y
Further, any definition must satisfy the following:
- identity
pure
id
<*>
v = v- composition
pure
(.)<*>
u<*>
v<*>
w = u<*>
(v<*>
w)- homomorphism
pure
f<*>
pure
x =pure
(f x)- interchange
u
<*>
pure
y =pure
($
y)<*>
u
The other methods have the following default definitions, which may be overridden with equivalent specialized implementations:
As a consequence of these laws, the Functor
instance for f
will satisfy
It may be useful to note that supposing
forall x y. p (q x y) = f x . g y
it follows from the above that
liftA2
p (liftA2
q u v) =liftA2
f u .liftA2
g v
If f
is also a Monad
, it should satisfy
(which implies that pure
and <*>
satisfy the applicative functor laws).
Lift a value.
(<*>) :: f (a -> b) -> f a -> f b infixl 4 #
Sequential application.
A few functors support an implementation of <*>
that is more
efficient than the default one.
liftA2 :: (a -> b -> c) -> f a -> f b -> f c #
Lift a binary function to actions.
Some functors support an implementation of liftA2
that is more
efficient than the default one. In particular, if fmap
is an
expensive operation, it is likely better to use liftA2
than to
fmap
over the structure and then use <*>
.
(*>) :: f a -> f b -> f b infixl 4 #
Sequence actions, discarding the value of the first argument.
(<*) :: f a -> f b -> f a infixl 4 #
Sequence actions, discarding the value of the second argument.
Instances
Applicative [] | Since: base-2.1 |
Applicative Maybe | Since: base-2.1 |
Applicative IO | Since: base-2.1 |
Applicative Par1 | Since: base-4.9.0.0 |
Applicative Q | |
Applicative Last | Since: base-4.9.0.0 |
Applicative Condition | |
Applicative IResult | |
Applicative Result | |
Applicative Parser | |
Applicative Complex | Since: base-4.9.0.0 |
Applicative Min | Since: base-4.9.0.0 |
Applicative Max | Since: base-4.9.0.0 |
Applicative First | Since: base-4.9.0.0 |
Applicative Option | Since: base-4.9.0.0 |
Applicative ZipList | f '<$>' 'ZipList' xs1 '<*>' ... '<*>' 'ZipList' xsN = 'ZipList' (zipWithN f xs1 ... xsN) where (\a b c -> stimes c [a, b]) <$> ZipList "abcd" <*> ZipList "567" <*> ZipList [1..] = ZipList (zipWith3 (\a b c -> stimes c [a, b]) "abcd" "567" [1..]) = ZipList {getZipList = ["a5","b6b6","c7c7c7"]} Since: base-2.1 |
Applicative Identity | Since: base-4.8.0.0 |
Applicative STM | Since: base-4.8.0.0 |
Applicative First | |
Applicative Last | |
Applicative Dual | Since: base-4.8.0.0 |
Applicative Sum | Since: base-4.8.0.0 |
Applicative Product | Since: base-4.8.0.0 |
Applicative Down | Since: base-4.11.0.0 |
Applicative ReadPrec | Since: base-4.6.0.0 |
Applicative ReadP | Since: base-4.6.0.0 |
Applicative NonEmpty | Since: base-4.9.0.0 |
Applicative Put | |
Applicative Tree | |
Applicative Seq | Since: containers-0.5.4 |
Applicative CryptoFailable | |
Defined in Crypto.Error.Types pure :: a -> CryptoFailable a # (<*>) :: CryptoFailable (a -> b) -> CryptoFailable a -> CryptoFailable b # liftA2 :: (a -> b -> c) -> CryptoFailable a -> CryptoFailable b -> CryptoFailable c # (*>) :: CryptoFailable a -> CryptoFailable b -> CryptoFailable b # (<*) :: CryptoFailable a -> CryptoFailable b -> CryptoFailable a # | |
Applicative DList | |
Applicative ReadM | |
Applicative Parser | |
Applicative ParserM | |
Applicative ParserResult | |
Defined in Options.Applicative.Types pure :: a -> ParserResult a # (<*>) :: ParserResult (a -> b) -> ParserResult a -> ParserResult b # liftA2 :: (a -> b -> c) -> ParserResult a -> ParserResult b -> ParserResult c # (*>) :: ParserResult a -> ParserResult b -> ParserResult b # (<*) :: ParserResult a -> ParserResult b -> ParserResult a # | |
Applicative Chunk | |
Applicative SmallArray | |
Defined in Data.Primitive.SmallArray pure :: a -> SmallArray a # (<*>) :: SmallArray (a -> b) -> SmallArray a -> SmallArray b # liftA2 :: (a -> b -> c) -> SmallArray a -> SmallArray b -> SmallArray c # (*>) :: SmallArray a -> SmallArray b -> SmallArray b # (<*) :: SmallArray a -> SmallArray b -> SmallArray a # | |
Applicative Array | |
Applicative Vector | |
Applicative Id | |
Applicative Box | |
Applicative Stream | |
Applicative P | Since: base-4.5.0.0 |
Applicative (Either e) | Since: base-3.0 |
Applicative (U1 :: * -> *) | Since: base-4.9.0.0 |
Monoid a => Applicative ((,) a) | For tuples, the ("hello ", (+15)) <*> ("world!", 2002) ("hello world!",2017) Since: base-2.1 |
Applicative (ST s) | Since: base-4.4.0.0 |
Applicative (Parser i) | |
Applicative (ST s) | Since: base-2.1 |
Monad m => Applicative (WrappedMonad m) | Since: base-2.1 |
Defined in Control.Applicative pure :: a -> WrappedMonad m a # (<*>) :: WrappedMonad m (a -> b) -> WrappedMonad m a -> WrappedMonad m b # liftA2 :: (a -> b -> c) -> WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m c # (*>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b # (<*) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m a # | |
Arrow a => Applicative (ArrowMonad a) | Since: base-4.6.0.0 |
Defined in Control.Arrow pure :: a0 -> ArrowMonad a a0 # (<*>) :: ArrowMonad a (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b # liftA2 :: (a0 -> b -> c) -> ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a c # (*>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b # (<*) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a a0 # | |
Applicative (Proxy :: * -> *) | Since: base-4.7.0.0 |
(Functor m, Monad m) => Applicative (MaybeT m) | |
Monad m => Applicative (ZipSource m) | |
Defined in Data.Conduit.Internal.Conduit | |
Applicative m => Applicative (ResourceT m) | |
Defined in Control.Monad.Trans.Resource.Internal | |
Applicative m => Applicative (ListT m) | |
Applicative (SetM s) | |
Applicative f => Applicative (Rec1 f) | Since: base-4.9.0.0 |
Arrow a => Applicative (WrappedArrow a b) | Since: base-2.1 |
Defined in Control.Applicative pure :: a0 -> WrappedArrow a b a0 # (<*>) :: WrappedArrow a b (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 # liftA2 :: (a0 -> b0 -> c) -> WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b c # (*>) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b b0 # (<*) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # | |
Monoid m => Applicative (Const m :: * -> *) | Since: base-2.0.1 |
Applicative f => Applicative (Alt f) | |
Applicative m => Applicative (IdentityT m) | |
Defined in Control.Monad.Trans.Identity | |
(Monoid w, Applicative m) => Applicative (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.Strict | |
(Monoid w, Applicative m) => Applicative (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.Lazy | |
(Functor m, Monad m) => Applicative (StateT s m) | |
Defined in Control.Monad.Trans.State.Strict | |
(Functor m, Monad m) => Applicative (StateT s m) | |
Defined in Control.Monad.Trans.State.Lazy | |
(Functor m, Monad m) => Applicative (ExceptT e m) | |
Defined in Control.Monad.Trans.Except | |
Monad m => Applicative (ZipSink i m) | |
Defined in Data.Conduit.Internal.Conduit | |
(Applicative f, Monad f) => Applicative (WhenMissing f x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal pure :: a -> WhenMissing f x a # (<*>) :: WhenMissing f x (a -> b) -> WhenMissing f x a -> WhenMissing f x b # liftA2 :: (a -> b -> c) -> WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x c # (*>) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x b # (<*) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x a # | |
(Functor m, Monad m) => Applicative (ErrorT e m) | |
Defined in Control.Monad.Trans.Error | |
(Profunctor p, Arrow p) => Applicative (Closure p a) | |
Defined in Data.Profunctor.Closed | |
(Profunctor p, Arrow p) => Applicative (Tambara p a) | |
Defined in Data.Profunctor.Strong | |
Applicative f => Applicative (Star f a) | |
Applicative (Costar f a) | |
Defined in Data.Profunctor.Types | |
Applicative (Tagged s) | |
(Monoid w, Functor m, Monad m) => Applicative (AccumT w m) | |
Defined in Control.Monad.Trans.Accum | |
(Functor m, Monad m) => Applicative (SelectT r m) | |
Defined in Control.Monad.Trans.Select | |
Applicative ((->) a :: * -> *) | Since: base-2.1 |
(Applicative f, Applicative g) => Applicative (f :*: g) | Since: base-4.9.0.0 |
(Applicative f, Applicative g) => Applicative (Product f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Product | |
Applicative (Cokleisli w a) | |
Defined in Control.Comonad pure :: a0 -> Cokleisli w a a0 # (<*>) :: Cokleisli w a (a0 -> b) -> Cokleisli w a a0 -> Cokleisli w a b # liftA2 :: (a0 -> b -> c) -> Cokleisli w a a0 -> Cokleisli w a b -> Cokleisli w a c # (*>) :: Cokleisli w a a0 -> Cokleisli w a b -> Cokleisli w a b # (<*) :: Cokleisli w a a0 -> Cokleisli w a b -> Cokleisli w a a0 # | |
Applicative m => Applicative (ReaderT r m) | |
Defined in Control.Monad.Trans.Reader | |
Applicative (ConduitT i o m) | |
Defined in Data.Conduit.Internal.Conduit pure :: a -> ConduitT i o m a # (<*>) :: ConduitT i o m (a -> b) -> ConduitT i o m a -> ConduitT i o m b # liftA2 :: (a -> b -> c) -> ConduitT i o m a -> ConduitT i o m b -> ConduitT i o m c # (*>) :: ConduitT i o m a -> ConduitT i o m b -> ConduitT i o m b # (<*) :: ConduitT i o m a -> ConduitT i o m b -> ConduitT i o m a # | |
Monad m => Applicative (ZipConduit i o m) | |
Defined in Data.Conduit.Internal.Conduit pure :: a -> ZipConduit i o m a # (<*>) :: ZipConduit i o m (a -> b) -> ZipConduit i o m a -> ZipConduit i o m b # liftA2 :: (a -> b -> c) -> ZipConduit i o m a -> ZipConduit i o m b -> ZipConduit i o m c # (*>) :: ZipConduit i o m a -> ZipConduit i o m b -> ZipConduit i o m b # (<*) :: ZipConduit i o m a -> ZipConduit i o m b -> ZipConduit i o m a # | |
(Monad f, Applicative f) => Applicative (WhenMatched f x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal pure :: a -> WhenMatched f x y a # (<*>) :: WhenMatched f x y (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b # liftA2 :: (a -> b -> c) -> WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y c # (*>) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y b # (<*) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y a # | |
(Applicative f, Monad f) => Applicative (WhenMissing f k x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal pure :: a -> WhenMissing f k x a # (<*>) :: WhenMissing f k x (a -> b) -> WhenMissing f k x a -> WhenMissing f k x b # liftA2 :: (a -> b -> c) -> WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x c # (*>) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x b # (<*) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x a # | |
Applicative (ContT r m) | |
Applicative f => Applicative (M1 i c f) | Since: base-4.9.0.0 |
(Applicative f, Applicative g) => Applicative (f :.: g) | Since: base-4.9.0.0 |
(Applicative f, Applicative g) => Applicative (Compose f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose | |
(Monoid w, Functor m, Monad m) => Applicative (RWST r w s m) | |
Defined in Control.Monad.Trans.RWS.Strict | |
(Monoid w, Functor m, Monad m) => Applicative (RWST r w s m) | |
Defined in Control.Monad.Trans.RWS.Lazy | |
(Monad f, Applicative f) => Applicative (WhenMatched f k x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal pure :: a -> WhenMatched f k x y a # (<*>) :: WhenMatched f k x y (a -> b) -> WhenMatched f k x y a -> WhenMatched f k x y b # liftA2 :: (a -> b -> c) -> WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y c # (*>) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y b # (<*) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y a # | |
Monad state => Applicative (Builder collection mutCollection step state err) | |
Defined in Basement.MutableBuilder pure :: a -> Builder collection mutCollection step state err a # (<*>) :: Builder collection mutCollection step state err (a -> b) -> Builder collection mutCollection step state err a -> Builder collection mutCollection step state err b # liftA2 :: (a -> b -> c) -> Builder collection mutCollection step state err a -> Builder collection mutCollection step state err b -> Builder collection mutCollection step state err c # (*>) :: Builder collection mutCollection step state err a -> Builder collection mutCollection step state err b -> Builder collection mutCollection step state err b # (<*) :: Builder collection mutCollection step state err a -> Builder collection mutCollection step state err b -> Builder collection mutCollection step state err a # | |
Monad m => Applicative (Pipe l i o u m) | |
Defined in Data.Conduit.Internal.Pipe pure :: a -> Pipe l i o u m a # (<*>) :: Pipe l i o u m (a -> b) -> Pipe l i o u m a -> Pipe l i o u m b # liftA2 :: (a -> b -> c) -> Pipe l i o u m a -> Pipe l i o u m b -> Pipe l i o u m c # (*>) :: Pipe l i o u m a -> Pipe l i o u m b -> Pipe l i o u m b # (<*) :: Pipe l i o u m a -> Pipe l i o u m b -> Pipe l i o u m a # |
mappend :: Monoid a => a -> a -> a #
An associative operation
NOTE: This method is redundant and has the default
implementation
since base-4.11.0.0.mappend
= '(<>)'
class Applicative f => Alternative (f :: * -> *) where #
A monoid on applicative functors.
If defined, some
and many
should be the least solutions
of the equations:
The identity of <|>
(<|>) :: f a -> f a -> f a infixl 3 #
An associative binary operation
One or more.
Zero or more.
Instances
(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 #
An infix synonym for fmap
.
The name of this operator is an allusion to $
.
Note the similarities between their types:
($) :: (a -> b) -> a -> b (<$>) :: Functor f => (a -> b) -> f a -> f b
Whereas $
is function application, <$>
is function
application lifted over a Functor
.
Examples
Convert from a
to a Maybe
Int
using Maybe
String
show
:
>>>
show <$> Nothing
Nothing>>>
show <$> Just 3
Just "3"
Convert from an
to an Either
Int
Int
Either
Int
String
using show
:
>>>
show <$> Left 17
Left 17>>>
show <$> Right 17
Right "17"
Double each element of a list:
>>>
(*2) <$> [1,2,3]
[2,4,6]
Apply even
to the second element of a pair:
>>>
even <$> (2,2)
(2,True)
optional :: Alternative f => f a -> f (Maybe a) #
One or none.
newtype WrappedMonad (m :: * -> *) a #
WrapMonad | |
|
Instances
newtype WrappedArrow (a :: * -> * -> *) b c #
WrapArrow | |
|
Instances
Lists, but with an Applicative
functor based on zipping.
ZipList | |
|
Instances
Functor ZipList | |
Applicative ZipList | f '<$>' 'ZipList' xs1 '<*>' ... '<*>' 'ZipList' xsN = 'ZipList' (zipWithN f xs1 ... xsN) where (\a b c -> stimes c [a, b]) <$> ZipList "abcd" <*> ZipList "567" <*> ZipList [1..] = ZipList (zipWith3 (\a b c -> stimes c [a, b]) "abcd" "567" [1..]) = ZipList {getZipList = ["a5","b6b6","c7c7c7"]} Since: base-2.1 |
Foldable ZipList | |
Defined in Control.Applicative fold :: Monoid m => ZipList m -> m # foldMap :: Monoid m => (a -> m) -> ZipList a -> m # foldr :: (a -> b -> b) -> b -> ZipList a -> b # foldr' :: (a -> b -> b) -> b -> ZipList a -> b # foldl :: (b -> a -> b) -> b -> ZipList a -> b # foldl' :: (b -> a -> b) -> b -> ZipList a -> b # foldr1 :: (a -> a -> a) -> ZipList a -> a # foldl1 :: (a -> a -> a) -> ZipList a -> a # elem :: Eq a => a -> ZipList a -> Bool # maximum :: Ord a => ZipList a -> a # minimum :: Ord a => ZipList a -> a # | |
Traversable ZipList | Since: base-4.9.0.0 |
Alternative ZipList | Since: base-4.11.0.0 |
NFData1 ZipList | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Eq a => Eq (ZipList a) | |
Ord a => Ord (ZipList a) | |
Defined in Control.Applicative | |
Read a => Read (ZipList a) | |
Show a => Show (ZipList a) | |
Generic (ZipList a) | |
NFData a => NFData (ZipList a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Generic1 ZipList | |
type Rep (ZipList a) | |
Defined in Control.Applicative | |
type Rep1 ZipList | |
Defined in Control.Applicative |
newtype Const a (b :: k) :: forall k. * -> k -> * #
The Const
functor.
Instances
Generic1 (Const a :: k -> *) | |
ToJSON2 (Const :: * -> * -> *) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> Const a b -> Value # liftToJSONList2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> [Const a b] -> Value # liftToEncoding2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> Const a b -> Encoding # liftToEncodingList2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> [Const a b] -> Encoding # | |
FromJSON2 (Const :: * -> * -> *) | |
Defined in Data.Aeson.Types.FromJSON | |
Bifoldable (Const :: * -> * -> *) | Since: base-4.10.0.0 |
Bifunctor (Const :: * -> * -> *) | Since: base-4.8.0.0 |
Eq2 (Const :: * -> * -> *) | Since: base-4.9.0.0 |
Ord2 (Const :: * -> * -> *) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Read2 (Const :: * -> * -> *) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (Const a b) # liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [Const a b] # liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (Const a b) # liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [Const a b] # | |
Show2 (Const :: * -> * -> *) | Since: base-4.9.0.0 |
NFData2 (Const :: * -> * -> *) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Hashable2 (Const :: * -> * -> *) | |
Defined in Data.Hashable.Class | |
Functor (Const m :: * -> *) | Since: base-2.1 |
Monoid m => Applicative (Const m :: * -> *) | Since: base-2.0.1 |
Foldable (Const m :: * -> *) | Since: base-4.7.0.0 |
Defined in Data.Functor.Const fold :: Monoid m0 => Const m m0 -> m0 # foldMap :: Monoid m0 => (a -> m0) -> Const m a -> m0 # foldr :: (a -> b -> b) -> b -> Const m a -> b # foldr' :: (a -> b -> b) -> b -> Const m a -> b # foldl :: (b -> a -> b) -> b -> Const m a -> b # foldl' :: (b -> a -> b) -> b -> Const m a -> b # foldr1 :: (a -> a -> a) -> Const m a -> a # foldl1 :: (a -> a -> a) -> Const m a -> a # elem :: Eq a => a -> Const m a -> Bool # maximum :: Ord a => Const m a -> a # minimum :: Ord a => Const m a -> a # | |
Traversable (Const m :: * -> *) | Since: base-4.7.0.0 |
ToJSON a => ToJSON1 (Const a :: * -> *) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> Const a a0 -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [Const a a0] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> Const a a0 -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [Const a a0] -> Encoding # | |
FromJSON a => FromJSON1 (Const a :: * -> *) | |
Eq a => Eq1 (Const a :: * -> *) | Since: base-4.9.0.0 |
Ord a => Ord1 (Const a :: * -> *) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Read a => Read1 (Const a :: * -> *) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Show a => Show1 (Const a :: * -> *) | Since: base-4.9.0.0 |
Contravariant (Const a :: * -> *) | |
NFData a => NFData1 (Const a :: * -> *) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Hashable a => Hashable1 (Const a :: * -> *) | |
Defined in Data.Hashable.Class | |
Bounded a => Bounded (Const a b) | |
Enum a => Enum (Const a b) | |
Defined in Data.Functor.Const succ :: Const a b -> Const a b # pred :: Const a b -> Const a b # fromEnum :: Const a b -> Int # enumFrom :: Const a b -> [Const a b] # enumFromThen :: Const a b -> Const a b -> [Const a b] # enumFromTo :: Const a b -> Const a b -> [Const a b] # enumFromThenTo :: Const a b -> Const a b -> Const a b -> [Const a b] # | |
Eq a => Eq (Const a b) | |
Floating a => Floating (Const a b) | |
Defined in Data.Functor.Const exp :: Const a b -> Const a b # log :: Const a b -> Const a b # sqrt :: Const a b -> Const a b # (**) :: Const a b -> Const a b -> Const a b # logBase :: Const a b -> Const a b -> Const a b # sin :: Const a b -> Const a b # cos :: Const a b -> Const a b # tan :: Const a b -> Const a b # asin :: Const a b -> Const a b # acos :: Const a b -> Const a b # atan :: Const a b -> Const a b # sinh :: Const a b -> Const a b # cosh :: Const a b -> Const a b # tanh :: Const a b -> Const a b # asinh :: Const a b -> Const a b # acosh :: Const a b -> Const a b # atanh :: Const a b -> Const a b # log1p :: Const a b -> Const a b # expm1 :: Const a b -> Const a b # | |
Fractional a => Fractional (Const a b) | |
Integral a => Integral (Const a b) | |
Defined in Data.Functor.Const | |
Num a => Num (Const a b) | |
Ord a => Ord (Const a b) | |
Defined in Data.Functor.Const | |
Read a => Read (Const a b) | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
Real a => Real (Const a b) | |
Defined in Data.Functor.Const toRational :: Const a b -> Rational # | |
RealFloat a => RealFloat (Const a b) | |
Defined in Data.Functor.Const floatRadix :: Const a b -> Integer # floatDigits :: Const a b -> Int # floatRange :: Const a b -> (Int, Int) # decodeFloat :: Const a b -> (Integer, Int) # encodeFloat :: Integer -> Int -> Const a b # exponent :: Const a b -> Int # significand :: Const a b -> Const a b # scaleFloat :: Int -> Const a b -> Const a b # isInfinite :: Const a b -> Bool # isDenormalized :: Const a b -> Bool # isNegativeZero :: Const a b -> Bool # | |
RealFrac a => RealFrac (Const a b) | |
Show a => Show (Const a b) | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
Ix a => Ix (Const a b) | |
Defined in Data.Functor.Const range :: (Const a b, Const a b) -> [Const a b] # index :: (Const a b, Const a b) -> Const a b -> Int # unsafeIndex :: (Const a b, Const a b) -> Const a b -> Int inRange :: (Const a b, Const a b) -> Const a b -> Bool # rangeSize :: (Const a b, Const a b) -> Int # unsafeRangeSize :: (Const a b, Const a b) -> Int | |
IsString a => IsString (Const a b) | Since: base-4.9.0.0 |
Defined in Data.String fromString :: String -> Const a b # | |
Generic (Const a b) | |
Semigroup a => Semigroup (Const a b) | |
Monoid a => Monoid (Const a b) | |
NFData a => NFData (Const a b) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Hashable a => Hashable (Const a b) | |
Defined in Data.Hashable.Class | |
ToJSON a => ToJSON (Const a b) | |
Defined in Data.Aeson.Types.ToJSON | |
FromJSON a => FromJSON (Const a b) | |
Storable a => Storable (Const a b) | |
Defined in Data.Functor.Const | |
Bits a => Bits (Const a b) | |
Defined in Data.Functor.Const (.&.) :: Const a b -> Const a b -> Const a b # (.|.) :: Const a b -> Const a b -> Const a b # xor :: Const a b -> Const a b -> Const a b # complement :: Const a b -> Const a b # shift :: Const a b -> Int -> Const a b # rotate :: Const a b -> Int -> Const a b # setBit :: Const a b -> Int -> Const a b # clearBit :: Const a b -> Int -> Const a b # complementBit :: Const a b -> Int -> Const a b # testBit :: Const a b -> Int -> Bool # bitSizeMaybe :: Const a b -> Maybe Int # isSigned :: Const a b -> Bool # shiftL :: Const a b -> Int -> Const a b # unsafeShiftL :: Const a b -> Int -> Const a b # shiftR :: Const a b -> Int -> Const a b # unsafeShiftR :: Const a b -> Int -> Const a b # rotateL :: Const a b -> Int -> Const a b # | |
FiniteBits a => FiniteBits (Const a b) | |
Defined in Data.Functor.Const finiteBitSize :: Const a b -> Int # countLeadingZeros :: Const a b -> Int # countTrailingZeros :: Const a b -> Int # | |
type Rep1 (Const a :: k -> *) | |
Defined in Data.Functor.Const | |
type Rep (Const a b) | |
Defined in Data.Functor.Const |
liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d #
Lift a ternary function to actions.
liftA :: Applicative f => (a -> b) -> f a -> f b #
(<**>) :: Applicative f => f a -> f (a -> b) -> f b infixl 4 #
A variant of <*>
with the arguments reversed.
renderFailure :: ParserFailure ParserHelp -> String -> (String, ExitCode) #
parserFailure :: ParserPrefs -> ParserInfo a -> ParseError -> [Context] -> ParserFailure ParserHelp #
Generate a ParserFailure
from a ParseError
in a given Context
.
This function can be used, for example, to show the help text for a parser:
handleParseResult . Failure $ parserFailure pprefs pinfo ShowHelpText mempty
:: ParserPrefs | Global preferences for this parser |
-> ParserInfo a | Description of the program to run |
-> [String] | Program arguments |
-> ParserResult a |
The most general way to run a program description in pure code.
getParseResult :: ParserResult a -> Maybe a #
Extract the actual result from a ParserResult
value.
This function returns Nothing
in case of errors. Possible error messages
or completion actions are simply discarded.
If you want to display error messages and invoke completion actions
appropriately, use handleParseResult
instead.
handleParseResult :: ParserResult a -> IO a #
Handle ParserResult
.
customExecParser :: ParserPrefs -> ParserInfo a -> IO a #
Run a program description with custom preferences.
execParser :: ParserInfo a -> IO a #
Run a program description.
Parse command line arguments. Display help text and exit if any parse error occurs.
hsubparser :: Mod CommandFields a -> Parser a #
Builder for a command parser with a "helper" option attached.
Used in the same way as subparser
, but includes a "--help|-h" inside
the subcommand.
A hidden "helper" option which always fails.
A common usage pattern is to apply this applicatively when
creating a ParserInfo
opts :: ParserInfo Sample opts = info (sample <**> helper) mempty
Default preferences.
prefs :: PrefsMod -> ParserPrefs #
Create a ParserPrefs
given a modifier
noBacktrack :: PrefsMod #
Turn off backtracking after subcommand is parsed.
Show the help text if the user enters only the program name or subcommand.
This will suppress a "Missing:" error and show the full usage instead if a user just types the name of the program.
Show full help text on any error.
Turn on disambiguation.
See https://github.com/pcapriotti/optparse-applicative#disambiguation
multiSuffix :: String -> PrefsMod #
Include a suffix to attach to the metavar when multiple values can be entered.
info :: Parser a -> InfoMod a -> ParserInfo a #
Create a ParserInfo
given a Parser
and a modifier.
forwardOptions :: InfoMod a #
Intersperse matched options and arguments normally, but allow unmatched options to be treated as positional arguments. This is sometimes useful if one is wrapping a third party cli tool and needs to pass options through, while also providing a handful of their own options. Not recommended in general as typos by the user may not yield a parse error and cause confusion.
noIntersperse :: InfoMod a #
Disable parsing of regular options after arguments. After a positional argument is parsed, all remaining options and arguments will be treated as a positional arguments. Not recommended in general as users often expect to be able to freely intersperse regular options and flags within command line options.
failureCode :: Int -> InfoMod a #
Specify an exit code if a parse error occurs.
option :: ReadM a -> Mod OptionFields a -> Parser a #
Builder for an option using the given reader.
This is a regular option, and should always have either a long
or
short
name specified in the modifiers (or both).
nameParser = option str ( long "name" <> short 'n' )
strOption :: IsString s => Mod OptionFields s -> Parser s #
Builder for an option taking a String
argument.
infoOption :: String -> Mod OptionFields (a -> a) -> Parser (a -> a) #
An option that always fails and displays a message.
abortOption :: ParseError -> Mod OptionFields (a -> a) -> Parser (a -> a) #
An option that always fails.
When this option is encountered, the option parser immediately aborts with
the given parse error. If you simply want to output a message, use
infoOption
instead.
:: a | active value |
-> Mod FlagFields a | option modifier |
-> Parser a |
Builder for a flag parser without a default value.
Same as flag
, but with no default value. In particular, this flag will
never parse successfully by itself.
It still makes sense to use it as part of a composite parser. For example
length <$> many (flag' () (short 't'))
is a parser that counts the number of "-t" arguments on the command line, alternatively
flag' True (long "on") <|> flag' False (long "off")
will require the user to enter '--on' or '--off' on the command line.
:: a | default value |
-> a | active value |
-> Mod FlagFields a | option modifier |
-> Parser a |
Builder for a flag parser.
A flag that switches from a "default value" to an "active value" when
encountered. For a simple boolean value, use switch
instead.
Note: Because this parser will never fail, it can not be used with
combinators such as some
or many
, as these combinators continue until
a failure occurs. See flag'
.
strArgument :: IsString s => Mod ArgumentFields s -> Parser s #
Builder for a String
argument.
subparser :: Mod CommandFields a -> Parser a #
Builder for a command parser. The command
modifier can be used to
specify individual commands.
completer :: HasCompleter f => Completer -> Mod f a #
Add a completer to an argument.
A completer is a function String -> IO String which, given a partial argument, returns all possible completions for that argument.
action :: HasCompleter f => String -> Mod f a #
Add a bash completion action. Common actions include file
and
directory
. See
http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#Programmable-Completion-Builtins
for a complete list.
completeWith :: HasCompleter f => [String] -> Mod f a #
Add a list of possible completion values.
commandGroup :: String -> Mod CommandFields a #
command :: String -> ParserInfo a -> Mod CommandFields a #
Add a command to a subparser option.
Suggested usage for multiple commands is to add them to a single subparser. e.g.
sample :: Parser Sample sample = subparser ( command "hello" (info hello (progDesc "Print greeting")) <> command "goodbye" (info goodbye (progDesc "Say goodbye")) )
style :: (Doc -> Doc) -> Mod f a #
Apply a function to the option description in the usage text.
import Options.Applicative.Help flag' () (short 't' <> style bold)
NOTE: This builder is more flexible than its name and example
allude. One of the motivating examples for its addition was to
used const
to completely replace the usage text of an option.
metavar :: HasMetavar f => String -> Mod f a #
Specify a metavariable for the argument.
Metavariables have no effect on the actual parser, and only serve to specify the symbolic name for an argument to be displayed in the help text.
noArgError :: ParseError -> Mod OptionFields a #
Specify the error to display when no argument is provided to this option.
showDefault :: Show a => Mod f a #
Show the default value for this option using its Show
instance.
showDefaultWith :: (a -> String) -> Mod f a #
Specify a function to show the default value for an option.
value :: HasValue f => a -> Mod f a #
Specify a default value for an option.
Note: Because this modifier means the parser will never fail,
do not use it with combinators such as some
or many
, as
these combinators continue until a failure occurs.
Careless use will thus result in a hang.
To display the default value, combine with showDefault or showDefaultWith.
eitherReader :: (String -> Either String a) -> ReadM a #
Convert a function producing an Either
into a reader.
As an example, one can create a ReadM from an attoparsec Parser easily with
import qualified Data.Attoparsec.Text as A import qualified Data.Text as T attoparsecReader :: A.Parser a -> ReadM a attoparsecReader p = eitherReader (A.parseOnly p . T.pack)
Modifier for ParserInfo
.
bashCompleter :: String -> Completer #
Run a compgen completion action.
Common actions include file
and
directory
. See
http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#Programmable-Completion-Builtins
for a complete list.
listCompleter :: [String] -> Completer #
Create a Completer
from a constant
list of strings.
data OptionFields a #
Instances
HasName OptionFields | |
Defined in Options.Applicative.Builder.Internal name :: OptName -> OptionFields a -> OptionFields a # | |
HasCompleter OptionFields | |
Defined in Options.Applicative.Builder.Internal modCompleter :: (Completer -> Completer) -> OptionFields a -> OptionFields a # | |
HasValue OptionFields | |
Defined in Options.Applicative.Builder.Internal hasValueDummy :: OptionFields a -> () # | |
HasMetavar OptionFields | |
Defined in Options.Applicative.Builder.Internal hasMetavarDummy :: OptionFields a -> () # |
data FlagFields a #
Instances
HasName FlagFields | |
Defined in Options.Applicative.Builder.Internal name :: OptName -> FlagFields a -> FlagFields a # |
data CommandFields a #
Instances
HasMetavar CommandFields | |
Defined in Options.Applicative.Builder.Internal hasMetavarDummy :: CommandFields a -> () # |
data ArgumentFields a #
Instances
HasCompleter ArgumentFields | |
Defined in Options.Applicative.Builder.Internal modCompleter :: (Completer -> Completer) -> ArgumentFields a -> ArgumentFields a # | |
HasValue ArgumentFields | |
Defined in Options.Applicative.Builder.Internal hasValueDummy :: ArgumentFields a -> () # | |
HasMetavar ArgumentFields | |
Defined in Options.Applicative.Builder.Internal hasMetavarDummy :: ArgumentFields a -> () # |
Instances
HasName OptionFields | |
Defined in Options.Applicative.Builder.Internal name :: OptName -> OptionFields a -> OptionFields a # | |
HasName FlagFields | |
Defined in Options.Applicative.Builder.Internal name :: OptName -> FlagFields a -> FlagFields a # |
class HasCompleter (f :: * -> *) #
Instances
HasCompleter OptionFields | |
Defined in Options.Applicative.Builder.Internal modCompleter :: (Completer -> Completer) -> OptionFields a -> OptionFields a # | |
HasCompleter ArgumentFields | |
Defined in Options.Applicative.Builder.Internal modCompleter :: (Completer -> Completer) -> ArgumentFields a -> ArgumentFields a # |
class HasValue (f :: * -> *) #
Instances
HasValue OptionFields | |
Defined in Options.Applicative.Builder.Internal hasValueDummy :: OptionFields a -> () # | |
HasValue ArgumentFields | |
Defined in Options.Applicative.Builder.Internal hasValueDummy :: ArgumentFields a -> () # |
class HasMetavar (f :: * -> *) #
Instances
HasMetavar OptionFields | |
Defined in Options.Applicative.Builder.Internal hasMetavarDummy :: OptionFields a -> () # | |
HasMetavar CommandFields | |
Defined in Options.Applicative.Builder.Internal hasMetavarDummy :: CommandFields a -> () # | |
HasMetavar ArgumentFields | |
Defined in Options.Applicative.Builder.Internal hasMetavarDummy :: ArgumentFields a -> () # |
An option modifier.
Option modifiers are values that represent a modification of the properties of an option.
The type parameter a
is the return type of the option, while f
is a
record containing its properties (e.g. OptionFields
for regular options,
FlagFields
for flags, etc...).
An option modifier consists of 3 elements:
- A field modifier, of the form
f a -> f a
. These are essentially (compositions of) setters for some of the properties supported byf
. - An optional default value and function to display it.
- A property modifier, of the form
OptProperties -> OptProperties
. This is just like the field modifier, but for properties applicable to any option.
Modifiers are instances of Monoid
, and can be composed as such.
One rarely needs to deal with modifiers directly, as most of the times it is
sufficient to pass them to builders (such as strOption
or flag
) to
create options (see Builder
).
overFailure :: (ParserHelp -> ParserHelp) -> ParserResult a -> ParserResult a #
readerError :: String -> ReadM a #
Abort option reader by exiting with an error message.
readerAbort :: ParseError -> ReadM a #
Abort option reader by exiting with a ParseError
.
data ParseError #
ErrorMsg String | |
InfoMsg String | |
ShowHelpText | |
UnknownError | |
MissingError IsCmdStart SomeParser | |
ExpectsArgError String | |
UnexpectedError String SomeParser |
Instances
Semigroup ParseError | |
Defined in Options.Applicative.Types (<>) :: ParseError -> ParseError -> ParseError # sconcat :: NonEmpty ParseError -> ParseError # stimes :: Integral b => b -> ParseError -> ParseError # | |
Monoid ParseError | |
Defined in Options.Applicative.Types mempty :: ParseError # mappend :: ParseError -> ParseError -> ParseError # mconcat :: [ParseError] -> ParseError # |
data ParserInfo a #
A full description for a runnable Parser
for a program.
ParserInfo | |
|
Instances
Functor ParserInfo | |
Defined in Options.Applicative.Types fmap :: (a -> b) -> ParserInfo a -> ParserInfo b # (<$) :: a -> ParserInfo b -> ParserInfo a # |
data ParserPrefs #
Global preferences for a top-level Parser
.
ParserPrefs | |
|
Instances
Eq ParserPrefs | |
Defined in Options.Applicative.Types (==) :: ParserPrefs -> ParserPrefs -> Bool # (/=) :: ParserPrefs -> ParserPrefs -> Bool # | |
Show ParserPrefs | |
Defined in Options.Applicative.Types showsPrec :: Int -> ParserPrefs -> ShowS # show :: ParserPrefs -> String # showList :: [ParserPrefs] -> ShowS # |
A newtype over 'ReaderT String Except', used by option readers.
Instances
Monad ReadM | |
Functor ReadM | |
MonadFail ReadM | |
Defined in Options.Applicative.Types | |
Applicative ReadM | |
MonadPlus ReadM | |
Alternative ReadM | |
newtype CompletionResult #
Instances
Show CompletionResult | |
Defined in Options.Applicative.Types showsPrec :: Int -> CompletionResult -> ShowS # show :: CompletionResult -> String # showList :: [CompletionResult] -> ShowS # |
newtype ParserFailure h #
ParserFailure | |
|
Instances
Functor ParserFailure | |
Defined in Options.Applicative.Types fmap :: (a -> b) -> ParserFailure a -> ParserFailure b # (<$) :: a -> ParserFailure b -> ParserFailure a # | |
Show h => Show (ParserFailure h) | |
Defined in Options.Applicative.Types showsPrec :: Int -> ParserFailure h -> ShowS # show :: ParserFailure h -> String # showList :: [ParserFailure h] -> ShowS # |
data ParserResult a #
Result of execParserPure
.
Instances
Monad ParserResult | |
Defined in Options.Applicative.Types (>>=) :: ParserResult a -> (a -> ParserResult b) -> ParserResult b # (>>) :: ParserResult a -> ParserResult b -> ParserResult b # return :: a -> ParserResult a # fail :: String -> ParserResult a # | |
Functor ParserResult | |
Defined in Options.Applicative.Types fmap :: (a -> b) -> ParserResult a -> ParserResult b # (<$) :: a -> ParserResult b -> ParserResult a # | |
Applicative ParserResult | |
Defined in Options.Applicative.Types pure :: a -> ParserResult a # (<*>) :: ParserResult (a -> b) -> ParserResult a -> ParserResult b # liftA2 :: (a -> b -> c) -> ParserResult a -> ParserResult b -> ParserResult c # (*>) :: ParserResult a -> ParserResult b -> ParserResult b # (<*) :: ParserResult a -> ParserResult b -> ParserResult a # | |
Show a => Show (ParserResult a) | |
Defined in Options.Applicative.Types showsPrec :: Int -> ParserResult a -> ShowS # show :: ParserResult a -> String # showList :: [ParserResult a] -> ShowS # |
data ParserHelp #
Instances
Show ParserHelp | |
Defined in Options.Applicative.Help.Types showsPrec :: Int -> ParserHelp -> ShowS # show :: ParserHelp -> String # showList :: [ParserHelp] -> ShowS # | |
Semigroup ParserHelp | |
Defined in Options.Applicative.Help.Types (<>) :: ParserHelp -> ParserHelp -> ParserHelp # sconcat :: NonEmpty ParserHelp -> ParserHelp # stimes :: Integral b => b -> ParserHelp -> ParserHelp # | |
Monoid ParserHelp | |
Defined in Options.Applicative.Help.Types mempty :: ParserHelp # mappend :: ParserHelp -> ParserHelp -> ParserHelp # mconcat :: [ParserHelp] -> ParserHelp # |