Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell98 |
Cloudy.Cli.Utils
Documentation
maybeOpt :: Show a => String -> a -> (Mod f a -> Parser a) -> Mod f a -> Parser (Maybe a) Source #
This lifts a option Parser
to a Parser
of Maybe
, allowing you to
specify a default value.
Given a call like:
maybeOpt
"Which foobar to use" "bazqux"strOption
(short
'f' <>metavar
"FOOBAR") ::Parser
(MaybeText
)
this returns Nothing
if the user doesn't specify the -f
option, and
Just
if the user does. It also shows that the default values is "bazqux"
.
Using maybeOpt
is different than just using the value
Mod
in order to
set a default value, since maybeOpt
returns Nothing
if the option was
not given on the command line (but it still shows the default value in the
--help
output.