{-# LANGUAGE CPP #-}
module Options.Applicative.Builder (
subparser,
strArgument,
argument,
flag,
flag',
switch,
abortOption,
infoOption,
strOption,
option,
short,
long,
help,
helpDoc,
value,
showDefaultWith,
showDefault,
metavar,
noArgError,
ParseError(..),
hidden,
internal,
style,
command,
commandGroup,
completeWith,
action,
completer,
idm,
mappend,
auto,
str,
maybeReader,
eitherReader,
disabled,
readerAbort,
readerError,
InfoMod,
fullDesc,
briefDesc,
header,
headerDoc,
footer,
footerDoc,
progDesc,
progDescDoc,
failureCode,
noIntersperse,
forwardOptions,
allPositional,
info,
PrefsMod,
multiSuffix,
disambiguate,
showHelpOnError,
showHelpOnEmpty,
noBacktrack,
subparserInline,
columns,
helpLongEquals,
helpShowGlobals,
helpIndent,
prefs,
defaultPrefs,
Mod,
ReadM,
OptionFields,
FlagFields,
ArgumentFields,
CommandFields,
HasName,
HasCompleter,
HasValue,
HasMetavar
) where
import Control.Applicative
#if __GLASGOW_HASKELL__ <= 802
import Data.Semigroup hiding (option)
#endif
import Data.String (fromString, IsString)
import Options.Applicative.Builder.Completer
import Options.Applicative.Builder.Internal
import Options.Applicative.Common
import Options.Applicative.Types
import Options.Applicative.Help.Pretty
import Options.Applicative.Help.Chunk
auto :: Read a => ReadM a
auto :: forall a. Read a => ReadM a
auto = (String -> Either String a) -> ReadM a
forall a. (String -> Either String a) -> ReadM a
eitherReader ((String -> Either String a) -> ReadM a)
-> (String -> Either String a) -> ReadM a
forall a b. (a -> b) -> a -> b
$ \String
arg -> case ReadS a
forall a. Read a => ReadS a
reads String
arg of
[(a
r, String
"")] -> a -> Either String a
forall a. a -> Either String a
forall (m :: * -> *) a. Monad m => a -> m a
return a
r
[(a, String)]
_ -> String -> Either String a
forall a b. a -> Either a b
Left (String -> Either String a) -> String -> Either String a
forall a b. (a -> b) -> a -> b
$ String
"cannot parse value `" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
arg String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"'"
str :: IsString s => ReadM s
str :: forall s. IsString s => ReadM s
str = String -> s
forall a. IsString a => String -> a
fromString (String -> s) -> ReadM String -> ReadM s
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM String
readerAsk
eitherReader :: (String -> Either String a) -> ReadM a
eitherReader :: forall a. (String -> Either String a) -> ReadM a
eitherReader String -> Either String a
f = ReadM String
readerAsk ReadM String -> (String -> ReadM a) -> ReadM a
forall a b. ReadM a -> (a -> ReadM b) -> ReadM b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (String -> ReadM a) -> (a -> ReadM a) -> Either String a -> ReadM a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either String -> ReadM a
forall a. String -> ReadM a
readerError a -> ReadM a
forall a. a -> ReadM a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either String a -> ReadM a)
-> (String -> Either String a) -> String -> ReadM a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Either String a
f
maybeReader :: (String -> Maybe a) -> ReadM a
maybeReader :: forall a. (String -> Maybe a) -> ReadM a
maybeReader String -> Maybe a
f = do
String
arg <- ReadM String
readerAsk
ReadM a -> (a -> ReadM a) -> Maybe a -> ReadM a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> ReadM a
forall a. String -> ReadM a
readerError (String -> ReadM a) -> String -> ReadM a
forall a b. (a -> b) -> a -> b
$ String
"cannot parse value `" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
arg String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"'") a -> ReadM a
forall a. a -> ReadM a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe a -> ReadM a) -> (String -> Maybe a) -> String -> ReadM a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Maybe a
f (String -> ReadM a) -> String -> ReadM a
forall a b. (a -> b) -> a -> b
$ String
arg
disabled :: ReadM a
disabled :: forall a. ReadM a
disabled = String -> ReadM a
forall a. String -> ReadM a
readerError String
"disabled option"
short :: HasName f => Char -> Mod f a
short :: forall (f :: * -> *) a. HasName f => Char -> Mod f a
short = (f a -> f a) -> Mod f a
forall (f :: * -> *) a. (f a -> f a) -> Mod f a
fieldMod ((f a -> f a) -> Mod f a)
-> (Char -> f a -> f a) -> Char -> Mod f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OptName -> f a -> f a
forall a. OptName -> f a -> f a
forall (f :: * -> *) a. HasName f => OptName -> f a -> f a
name (OptName -> f a -> f a) -> (Char -> OptName) -> Char -> f a -> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> OptName
OptShort
long :: HasName f => String -> Mod f a
long :: forall (f :: * -> *) a. HasName f => String -> Mod f a
long = (f a -> f a) -> Mod f a
forall (f :: * -> *) a. (f a -> f a) -> Mod f a
fieldMod ((f a -> f a) -> Mod f a)
-> (String -> f a -> f a) -> String -> Mod f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OptName -> f a -> f a
forall a. OptName -> f a -> f a
forall (f :: * -> *) a. HasName f => OptName -> f a -> f a
name (OptName -> f a -> f a)
-> (String -> OptName) -> String -> f a -> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> OptName
OptLong
value :: HasValue f => a -> Mod f a
value :: forall (f :: * -> *) a. HasValue f => a -> Mod f a
value a
x = (f a -> f a)
-> DefaultProp a -> (OptProperties -> OptProperties) -> Mod f a
forall (f :: * -> *) a.
(f a -> f a)
-> DefaultProp a -> (OptProperties -> OptProperties) -> Mod f a
Mod f a -> f a
forall a. a -> a
id (Maybe a -> Maybe (a -> String) -> DefaultProp a
forall a. Maybe a -> Maybe (a -> String) -> DefaultProp a
DefaultProp (a -> Maybe a
forall a. a -> Maybe a
Just a
x) Maybe (a -> String)
forall a. Maybe a
Nothing) OptProperties -> OptProperties
forall a. a -> a
id
showDefaultWith :: (a -> String) -> Mod f a
showDefaultWith :: forall a (f :: * -> *). (a -> String) -> Mod f a
showDefaultWith a -> String
s = (f a -> f a)
-> DefaultProp a -> (OptProperties -> OptProperties) -> Mod f a
forall (f :: * -> *) a.
(f a -> f a)
-> DefaultProp a -> (OptProperties -> OptProperties) -> Mod f a
Mod f a -> f a
forall a. a -> a
id (Maybe a -> Maybe (a -> String) -> DefaultProp a
forall a. Maybe a -> Maybe (a -> String) -> DefaultProp a
DefaultProp Maybe a
forall a. Maybe a
Nothing ((a -> String) -> Maybe (a -> String)
forall a. a -> Maybe a
Just a -> String
s)) OptProperties -> OptProperties
forall a. a -> a
id
showDefault :: Show a => Mod f a
showDefault :: forall a (f :: * -> *). Show a => Mod f a
showDefault = (a -> String) -> Mod f a
forall a (f :: * -> *). (a -> String) -> Mod f a
showDefaultWith a -> String
forall a. Show a => a -> String
show
help :: String -> Mod f a
help :: forall (f :: * -> *) a. String -> Mod f a
help String
s = (OptProperties -> OptProperties) -> Mod f a
forall (f :: * -> *) a. (OptProperties -> OptProperties) -> Mod f a
optionMod ((OptProperties -> OptProperties) -> Mod f a)
-> (OptProperties -> OptProperties) -> Mod f a
forall a b. (a -> b) -> a -> b
$ \OptProperties
p -> OptProperties
p { propHelp = paragraph s }
helpDoc :: Maybe Doc -> Mod f a
helpDoc :: forall (f :: * -> *) a. Maybe Doc -> Mod f a
helpDoc Maybe Doc
doc = (OptProperties -> OptProperties) -> Mod f a
forall (f :: * -> *) a. (OptProperties -> OptProperties) -> Mod f a
optionMod ((OptProperties -> OptProperties) -> Mod f a)
-> (OptProperties -> OptProperties) -> Mod f a
forall a b. (a -> b) -> a -> b
$ \OptProperties
p -> OptProperties
p { propHelp = Chunk doc }
noArgError :: ParseError -> Mod OptionFields a
noArgError :: forall a. ParseError -> Mod OptionFields a
noArgError ParseError
e = (OptionFields a -> OptionFields a) -> Mod OptionFields a
forall (f :: * -> *) a. (f a -> f a) -> Mod f a
fieldMod ((OptionFields a -> OptionFields a) -> Mod OptionFields a)
-> (OptionFields a -> OptionFields a) -> Mod OptionFields a
forall a b. (a -> b) -> a -> b
$ \OptionFields a
p -> OptionFields a
p { optNoArgError = const e }
metavar :: HasMetavar f => String -> Mod f a
metavar :: forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
var = (OptProperties -> OptProperties) -> Mod f a
forall (f :: * -> *) a. (OptProperties -> OptProperties) -> Mod f a
optionMod ((OptProperties -> OptProperties) -> Mod f a)
-> (OptProperties -> OptProperties) -> Mod f a
forall a b. (a -> b) -> a -> b
$ \OptProperties
p -> OptProperties
p { propMetaVar = var }
hidden :: Mod f a
hidden :: forall (f :: * -> *) a. Mod f a
hidden = (OptProperties -> OptProperties) -> Mod f a
forall (f :: * -> *) a. (OptProperties -> OptProperties) -> Mod f a
optionMod ((OptProperties -> OptProperties) -> Mod f a)
-> (OptProperties -> OptProperties) -> Mod f a
forall a b. (a -> b) -> a -> b
$ \OptProperties
p ->
OptProperties
p { propVisibility = min Hidden (propVisibility p) }
style :: ( Doc -> Doc ) -> Mod f a
style :: forall (f :: * -> *) a. (Doc -> Doc) -> Mod f a
style Doc -> Doc
x = (OptProperties -> OptProperties) -> Mod f a
forall (f :: * -> *) a. (OptProperties -> OptProperties) -> Mod f a
optionMod ((OptProperties -> OptProperties) -> Mod f a)
-> (OptProperties -> OptProperties) -> Mod f a
forall a b. (a -> b) -> a -> b
$ \OptProperties
p ->
OptProperties
p { propDescMod = Just x }
command :: String -> ParserInfo a -> Mod CommandFields a
command :: forall a. String -> ParserInfo a -> Mod CommandFields a
command String
cmd ParserInfo a
pinfo = (CommandFields a -> CommandFields a) -> Mod CommandFields a
forall (f :: * -> *) a. (f a -> f a) -> Mod f a
fieldMod ((CommandFields a -> CommandFields a) -> Mod CommandFields a)
-> (CommandFields a -> CommandFields a) -> Mod CommandFields a
forall a b. (a -> b) -> a -> b
$ \CommandFields a
p ->
CommandFields a
p { cmdCommands = (cmd, pinfo) : cmdCommands p }
commandGroup :: String -> Mod CommandFields a
commandGroup :: forall a. String -> Mod CommandFields a
commandGroup String
g = (CommandFields a -> CommandFields a) -> Mod CommandFields a
forall (f :: * -> *) a. (f a -> f a) -> Mod f a
fieldMod ((CommandFields a -> CommandFields a) -> Mod CommandFields a)
-> (CommandFields a -> CommandFields a) -> Mod CommandFields a
forall a b. (a -> b) -> a -> b
$ \CommandFields a
p ->
CommandFields a
p { cmdGroup = Just g }
completeWith :: HasCompleter f => [String] -> Mod f a
completeWith :: forall (f :: * -> *) a. HasCompleter f => [String] -> Mod f a
completeWith = Completer -> Mod f a
forall (f :: * -> *) a. HasCompleter f => Completer -> Mod f a
completer (Completer -> Mod f a)
-> ([String] -> Completer) -> [String] -> Mod f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> Completer
listCompleter
action :: HasCompleter f => String -> Mod f a
action :: forall (f :: * -> *) a. HasCompleter f => String -> Mod f a
action = Completer -> Mod f a
forall (f :: * -> *) a. HasCompleter f => Completer -> Mod f a
completer (Completer -> Mod f a)
-> (String -> Completer) -> String -> Mod f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Completer
bashCompleter
completer :: HasCompleter f => Completer -> Mod f a
completer :: forall (f :: * -> *) a. HasCompleter f => Completer -> Mod f a
completer Completer
f = (f a -> f a) -> Mod f a
forall (f :: * -> *) a. (f a -> f a) -> Mod f a
fieldMod ((f a -> f a) -> Mod f a) -> (f a -> f a) -> Mod f a
forall a b. (a -> b) -> a -> b
$ (Completer -> Completer) -> f a -> f a
forall a. (Completer -> Completer) -> f a -> f a
forall (f :: * -> *) a.
HasCompleter f =>
(Completer -> Completer) -> f a -> f a
modCompleter (Completer -> Completer -> Completer
forall a. Monoid a => a -> a -> a
`mappend` Completer
f)
subparser :: Mod CommandFields a -> Parser a
subparser :: forall a. Mod CommandFields a -> Parser a
subparser Mod CommandFields a
m = DefaultProp a
-> (OptProperties -> OptProperties) -> OptReader a -> Parser a
forall a.
DefaultProp a
-> (OptProperties -> OptProperties) -> OptReader a -> Parser a
mkParser DefaultProp a
d OptProperties -> OptProperties
g OptReader a
rdr
where
Mod CommandFields a -> CommandFields a
_ DefaultProp a
d OptProperties -> OptProperties
g = String -> Mod CommandFields a
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"COMMAND" Mod CommandFields a -> Mod CommandFields a -> Mod CommandFields a
forall a. Monoid a => a -> a -> a
`mappend` Mod CommandFields a
m
(Maybe String
groupName, [(String, ParserInfo a)]
cmds) = Mod CommandFields a -> (Maybe String, [(String, ParserInfo a)])
forall a.
Mod CommandFields a -> (Maybe String, [(String, ParserInfo a)])
mkCommand Mod CommandFields a
m
rdr :: OptReader a
rdr = Maybe String -> [(String, ParserInfo a)] -> OptReader a
forall a. Maybe String -> [(String, ParserInfo a)] -> OptReader a
CmdReader Maybe String
groupName [(String, ParserInfo a)]
cmds
argument :: ReadM a -> Mod ArgumentFields a -> Parser a
argument :: forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM a
p Mod ArgumentFields a
m = DefaultProp a
-> (OptProperties -> OptProperties) -> OptReader a -> Parser a
forall a.
DefaultProp a
-> (OptProperties -> OptProperties) -> OptReader a -> Parser a
mkParser DefaultProp a
d OptProperties -> OptProperties
g (CReader a -> OptReader a
forall a. CReader a -> OptReader a
ArgReader CReader a
rdr)
where
(Mod ArgumentFields a -> ArgumentFields a
f DefaultProp a
d OptProperties -> OptProperties
g) = Mod ArgumentFields a
forall (f :: * -> *) a. Mod f a
noGlobal Mod ArgumentFields a
-> Mod ArgumentFields a -> Mod ArgumentFields a
forall a. Monoid a => a -> a -> a
`mappend` Mod ArgumentFields a
m
ArgumentFields Completer
compl = ArgumentFields a -> ArgumentFields a
f (Completer -> ArgumentFields a
forall a. Completer -> ArgumentFields a
ArgumentFields Completer
forall a. Monoid a => a
mempty)
rdr :: CReader a
rdr = Completer -> ReadM a -> CReader a
forall a. Completer -> ReadM a -> CReader a
CReader Completer
compl ReadM a
p
strArgument :: IsString s => Mod ArgumentFields s -> Parser s
strArgument :: forall s. IsString s => Mod ArgumentFields s -> Parser s
strArgument = ReadM s -> Mod ArgumentFields s -> Parser s
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM s
forall s. IsString s => ReadM s
str
flag :: a
-> a
-> Mod FlagFields a
-> Parser a
flag :: forall a. a -> a -> Mod FlagFields a -> Parser a
flag a
defv a
actv Mod FlagFields a
m = a -> Mod FlagFields a -> Parser a
forall a. a -> Mod FlagFields a -> Parser a
flag' a
actv Mod FlagFields a
m Parser a -> Parser a -> Parser a
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> a -> Parser a
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
defv
flag' :: a
-> Mod FlagFields a
-> Parser a
flag' :: forall a. a -> Mod FlagFields a -> Parser a
flag' a
actv (Mod FlagFields a -> FlagFields a
f DefaultProp a
d OptProperties -> OptProperties
g) = DefaultProp a
-> (OptProperties -> OptProperties) -> OptReader a -> Parser a
forall a.
DefaultProp a
-> (OptProperties -> OptProperties) -> OptReader a -> Parser a
mkParser DefaultProp a
d OptProperties -> OptProperties
g OptReader a
rdr
where
rdr :: OptReader a
rdr = let fields :: FlagFields a
fields = FlagFields a -> FlagFields a
f ([OptName] -> a -> FlagFields a
forall a. [OptName] -> a -> FlagFields a
FlagFields [] a
actv)
in [OptName] -> a -> OptReader a
forall a. [OptName] -> a -> OptReader a
FlagReader (FlagFields a -> [OptName]
forall a. FlagFields a -> [OptName]
flagNames FlagFields a
fields)
(FlagFields a -> a
forall a. FlagFields a -> a
flagActive FlagFields a
fields)
switch :: Mod FlagFields Bool -> Parser Bool
switch :: Mod FlagFields Bool -> Parser Bool
switch = Bool -> Bool -> Mod FlagFields Bool -> Parser Bool
forall a. a -> a -> Mod FlagFields a -> Parser a
flag Bool
False Bool
True
abortOption :: ParseError -> Mod OptionFields (a -> a) -> Parser (a -> a)
abortOption :: forall a.
ParseError -> Mod OptionFields (a -> a) -> Parser (a -> a)
abortOption ParseError
err Mod OptionFields (a -> a)
m = ReadM (a -> a) -> Mod OptionFields (a -> a) -> Parser (a -> a)
forall a. ReadM a -> Mod OptionFields a -> Parser a
option (ParseError -> ReadM (a -> a)
forall a. ParseError -> ReadM a
readerAbort ParseError
err) (Mod OptionFields (a -> a) -> Parser (a -> a))
-> (Mod OptionFields (a -> a) -> Mod OptionFields (a -> a))
-> Mod OptionFields (a -> a)
-> Parser (a -> a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Mod OptionFields (a -> a)
-> Mod OptionFields (a -> a) -> Mod OptionFields (a -> a)
forall a. Monoid a => a -> a -> a
`mappend` Mod OptionFields (a -> a)
m) (Mod OptionFields (a -> a) -> Parser (a -> a))
-> Mod OptionFields (a -> a) -> Parser (a -> a)
forall a b. (a -> b) -> a -> b
$ [Mod OptionFields (a -> a)] -> Mod OptionFields (a -> a)
forall a. Monoid a => [a] -> a
mconcat
[ ParseError -> Mod OptionFields (a -> a)
forall a. ParseError -> Mod OptionFields a
noArgError ParseError
err
, (a -> a) -> Mod OptionFields (a -> a)
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value a -> a
forall a. a -> a
id
, String -> Mod OptionFields (a -> a)
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"" ]
infoOption :: String -> Mod OptionFields (a -> a) -> Parser (a -> a)
infoOption :: forall a. String -> Mod OptionFields (a -> a) -> Parser (a -> a)
infoOption = ParseError -> Mod OptionFields (a -> a) -> Parser (a -> a)
forall a.
ParseError -> Mod OptionFields (a -> a) -> Parser (a -> a)
abortOption (ParseError -> Mod OptionFields (a -> a) -> Parser (a -> a))
-> (String -> ParseError)
-> String
-> Mod OptionFields (a -> a)
-> Parser (a -> a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ParseError
InfoMsg
strOption :: IsString s => Mod OptionFields s -> Parser s
strOption :: forall s. IsString s => Mod OptionFields s -> Parser s
strOption = ReadM s -> Mod OptionFields s -> Parser s
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM s
forall s. IsString s => ReadM s
str
option :: ReadM a -> Mod OptionFields a -> Parser a
option :: forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM a
r Mod OptionFields a
m = DefaultProp a
-> (OptProperties -> OptProperties) -> OptReader a -> Parser a
forall a.
DefaultProp a
-> (OptProperties -> OptProperties) -> OptReader a -> Parser a
mkParser DefaultProp a
d OptProperties -> OptProperties
g OptReader a
rdr
where
Mod OptionFields a -> OptionFields a
f DefaultProp a
d OptProperties -> OptProperties
g = String -> Mod OptionFields a
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"ARG" Mod OptionFields a -> Mod OptionFields a -> Mod OptionFields a
forall a. Monoid a => a -> a -> a
`mappend` Mod OptionFields a
m
fields :: OptionFields a
fields = OptionFields a -> OptionFields a
f ([OptName] -> Completer -> (String -> ParseError) -> OptionFields a
forall a.
[OptName] -> Completer -> (String -> ParseError) -> OptionFields a
OptionFields [] Completer
forall a. Monoid a => a
mempty String -> ParseError
ExpectsArgError)
crdr :: CReader a
crdr = Completer -> ReadM a -> CReader a
forall a. Completer -> ReadM a -> CReader a
CReader (OptionFields a -> Completer
forall a. OptionFields a -> Completer
optCompleter OptionFields a
fields) ReadM a
r
rdr :: OptReader a
rdr = [OptName] -> CReader a -> (String -> ParseError) -> OptReader a
forall a.
[OptName] -> CReader a -> (String -> ParseError) -> OptReader a
OptReader (OptionFields a -> [OptName]
forall a. OptionFields a -> [OptName]
optNames OptionFields a
fields) CReader a
crdr (OptionFields a -> String -> ParseError
forall a. OptionFields a -> String -> ParseError
optNoArgError OptionFields a
fields)
newtype InfoMod a = InfoMod
{ forall a. InfoMod a -> ParserInfo a -> ParserInfo a
applyInfoMod :: ParserInfo a -> ParserInfo a }
instance Monoid (InfoMod a) where
mempty :: InfoMod a
mempty = (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod ParserInfo a -> ParserInfo a
forall a. a -> a
id
mappend :: InfoMod a -> InfoMod a -> InfoMod a
mappend = InfoMod a -> InfoMod a -> InfoMod a
forall a. Semigroup a => a -> a -> a
(<>)
instance Semigroup (InfoMod a) where
InfoMod a
m1 <> :: InfoMod a -> InfoMod a -> InfoMod a
<> InfoMod a
m2 = (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod ((ParserInfo a -> ParserInfo a) -> InfoMod a)
-> (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a b. (a -> b) -> a -> b
$ InfoMod a -> ParserInfo a -> ParserInfo a
forall a. InfoMod a -> ParserInfo a -> ParserInfo a
applyInfoMod InfoMod a
m2 (ParserInfo a -> ParserInfo a)
-> (ParserInfo a -> ParserInfo a) -> ParserInfo a -> ParserInfo a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InfoMod a -> ParserInfo a -> ParserInfo a
forall a. InfoMod a -> ParserInfo a -> ParserInfo a
applyInfoMod InfoMod a
m1
fullDesc :: InfoMod a
fullDesc :: forall a. InfoMod a
fullDesc = (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod ((ParserInfo a -> ParserInfo a) -> InfoMod a)
-> (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a b. (a -> b) -> a -> b
$ \ParserInfo a
i -> ParserInfo a
i { infoFullDesc = True }
briefDesc :: InfoMod a
briefDesc :: forall a. InfoMod a
briefDesc = (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod ((ParserInfo a -> ParserInfo a) -> InfoMod a)
-> (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a b. (a -> b) -> a -> b
$ \ParserInfo a
i -> ParserInfo a
i { infoFullDesc = False }
header :: String -> InfoMod a
String
s = (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod ((ParserInfo a -> ParserInfo a) -> InfoMod a)
-> (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a b. (a -> b) -> a -> b
$ \ParserInfo a
i -> ParserInfo a
i { infoHeader = paragraph s }
headerDoc :: Maybe Doc -> InfoMod a
Maybe Doc
doc = (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod ((ParserInfo a -> ParserInfo a) -> InfoMod a)
-> (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a b. (a -> b) -> a -> b
$ \ParserInfo a
i -> ParserInfo a
i { infoHeader = Chunk doc }
footer :: String -> InfoMod a
String
s = (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod ((ParserInfo a -> ParserInfo a) -> InfoMod a)
-> (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a b. (a -> b) -> a -> b
$ \ParserInfo a
i -> ParserInfo a
i { infoFooter = paragraph s }
footerDoc :: Maybe Doc -> InfoMod a
Maybe Doc
doc = (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod ((ParserInfo a -> ParserInfo a) -> InfoMod a)
-> (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a b. (a -> b) -> a -> b
$ \ParserInfo a
i -> ParserInfo a
i { infoFooter = Chunk doc }
progDesc :: String -> InfoMod a
progDesc :: forall a. String -> InfoMod a
progDesc String
s = (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod ((ParserInfo a -> ParserInfo a) -> InfoMod a)
-> (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a b. (a -> b) -> a -> b
$ \ParserInfo a
i -> ParserInfo a
i { infoProgDesc = paragraph s }
progDescDoc :: Maybe Doc -> InfoMod a
progDescDoc :: forall a. Maybe Doc -> InfoMod a
progDescDoc Maybe Doc
doc = (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod ((ParserInfo a -> ParserInfo a) -> InfoMod a)
-> (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a b. (a -> b) -> a -> b
$ \ParserInfo a
i -> ParserInfo a
i { infoProgDesc = Chunk doc }
failureCode :: Int -> InfoMod a
failureCode :: forall a. Int -> InfoMod a
failureCode Int
n = (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod ((ParserInfo a -> ParserInfo a) -> InfoMod a)
-> (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a b. (a -> b) -> a -> b
$ \ParserInfo a
i -> ParserInfo a
i { infoFailureCode = n }
noIntersperse :: InfoMod a
noIntersperse :: forall a. InfoMod a
noIntersperse = (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod ((ParserInfo a -> ParserInfo a) -> InfoMod a)
-> (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a b. (a -> b) -> a -> b
$ \ParserInfo a
p -> ParserInfo a
p { infoPolicy = NoIntersperse }
forwardOptions :: InfoMod a
forwardOptions :: forall a. InfoMod a
forwardOptions = (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod ((ParserInfo a -> ParserInfo a) -> InfoMod a)
-> (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a b. (a -> b) -> a -> b
$ \ParserInfo a
p -> ParserInfo a
p { infoPolicy = ForwardOptions }
allPositional :: InfoMod a
allPositional :: forall a. InfoMod a
allPositional = (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod ((ParserInfo a -> ParserInfo a) -> InfoMod a)
-> (ParserInfo a -> ParserInfo a) -> InfoMod a
forall a b. (a -> b) -> a -> b
$ \ParserInfo a
p -> ParserInfo a
p { infoPolicy = AllPositionals }
info :: Parser a -> InfoMod a -> ParserInfo a
info :: forall a. Parser a -> InfoMod a -> ParserInfo a
info Parser a
parser InfoMod a
m = InfoMod a -> ParserInfo a -> ParserInfo a
forall a. InfoMod a -> ParserInfo a -> ParserInfo a
applyInfoMod InfoMod a
m ParserInfo a
base
where
base :: ParserInfo a
base = ParserInfo
{ infoParser :: Parser a
infoParser = Parser a
parser
, infoFullDesc :: Bool
infoFullDesc = Bool
True
, infoProgDesc :: Chunk Doc
infoProgDesc = Chunk Doc
forall a. Monoid a => a
mempty
, infoHeader :: Chunk Doc
infoHeader = Chunk Doc
forall a. Monoid a => a
mempty
, infoFooter :: Chunk Doc
infoFooter = Chunk Doc
forall a. Monoid a => a
mempty
, infoFailureCode :: Int
infoFailureCode = Int
1
, infoPolicy :: ArgPolicy
infoPolicy = ArgPolicy
Intersperse }
newtype PrefsMod = PrefsMod
{ PrefsMod -> ParserPrefs -> ParserPrefs
applyPrefsMod :: ParserPrefs -> ParserPrefs }
instance Monoid PrefsMod where
mempty :: PrefsMod
mempty = (ParserPrefs -> ParserPrefs) -> PrefsMod
PrefsMod ParserPrefs -> ParserPrefs
forall a. a -> a
id
mappend :: PrefsMod -> PrefsMod -> PrefsMod
mappend = PrefsMod -> PrefsMod -> PrefsMod
forall a. Semigroup a => a -> a -> a
(<>)
instance Semigroup PrefsMod where
PrefsMod
m1 <> :: PrefsMod -> PrefsMod -> PrefsMod
<> PrefsMod
m2 = (ParserPrefs -> ParserPrefs) -> PrefsMod
PrefsMod ((ParserPrefs -> ParserPrefs) -> PrefsMod)
-> (ParserPrefs -> ParserPrefs) -> PrefsMod
forall a b. (a -> b) -> a -> b
$ PrefsMod -> ParserPrefs -> ParserPrefs
applyPrefsMod PrefsMod
m2 (ParserPrefs -> ParserPrefs)
-> (ParserPrefs -> ParserPrefs) -> ParserPrefs -> ParserPrefs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PrefsMod -> ParserPrefs -> ParserPrefs
applyPrefsMod PrefsMod
m1
multiSuffix :: String -> PrefsMod
multiSuffix :: String -> PrefsMod
multiSuffix String
s = (ParserPrefs -> ParserPrefs) -> PrefsMod
PrefsMod ((ParserPrefs -> ParserPrefs) -> PrefsMod)
-> (ParserPrefs -> ParserPrefs) -> PrefsMod
forall a b. (a -> b) -> a -> b
$ \ParserPrefs
p -> ParserPrefs
p { prefMultiSuffix = s }
disambiguate :: PrefsMod
disambiguate :: PrefsMod
disambiguate = (ParserPrefs -> ParserPrefs) -> PrefsMod
PrefsMod ((ParserPrefs -> ParserPrefs) -> PrefsMod)
-> (ParserPrefs -> ParserPrefs) -> PrefsMod
forall a b. (a -> b) -> a -> b
$ \ParserPrefs
p -> ParserPrefs
p { prefDisambiguate = True }
showHelpOnError :: PrefsMod
showHelpOnError :: PrefsMod
showHelpOnError = (ParserPrefs -> ParserPrefs) -> PrefsMod
PrefsMod ((ParserPrefs -> ParserPrefs) -> PrefsMod)
-> (ParserPrefs -> ParserPrefs) -> PrefsMod
forall a b. (a -> b) -> a -> b
$ \ParserPrefs
p -> ParserPrefs
p { prefShowHelpOnError = True }
showHelpOnEmpty :: PrefsMod
showHelpOnEmpty :: PrefsMod
showHelpOnEmpty = (ParserPrefs -> ParserPrefs) -> PrefsMod
PrefsMod ((ParserPrefs -> ParserPrefs) -> PrefsMod)
-> (ParserPrefs -> ParserPrefs) -> PrefsMod
forall a b. (a -> b) -> a -> b
$ \ParserPrefs
p -> ParserPrefs
p { prefShowHelpOnEmpty = True }
noBacktrack :: PrefsMod
noBacktrack :: PrefsMod
noBacktrack = (ParserPrefs -> ParserPrefs) -> PrefsMod
PrefsMod ((ParserPrefs -> ParserPrefs) -> PrefsMod)
-> (ParserPrefs -> ParserPrefs) -> PrefsMod
forall a b. (a -> b) -> a -> b
$ \ParserPrefs
p -> ParserPrefs
p { prefBacktrack = NoBacktrack }
subparserInline :: PrefsMod
subparserInline :: PrefsMod
subparserInline = (ParserPrefs -> ParserPrefs) -> PrefsMod
PrefsMod ((ParserPrefs -> ParserPrefs) -> PrefsMod)
-> (ParserPrefs -> ParserPrefs) -> PrefsMod
forall a b. (a -> b) -> a -> b
$ \ParserPrefs
p -> ParserPrefs
p { prefBacktrack = SubparserInline }
columns :: Int -> PrefsMod
columns :: Int -> PrefsMod
columns Int
cols = (ParserPrefs -> ParserPrefs) -> PrefsMod
PrefsMod ((ParserPrefs -> ParserPrefs) -> PrefsMod)
-> (ParserPrefs -> ParserPrefs) -> PrefsMod
forall a b. (a -> b) -> a -> b
$ \ParserPrefs
p -> ParserPrefs
p { prefColumns = cols }
helpLongEquals :: PrefsMod
helpLongEquals :: PrefsMod
helpLongEquals = (ParserPrefs -> ParserPrefs) -> PrefsMod
PrefsMod ((ParserPrefs -> ParserPrefs) -> PrefsMod)
-> (ParserPrefs -> ParserPrefs) -> PrefsMod
forall a b. (a -> b) -> a -> b
$ \ParserPrefs
p -> ParserPrefs
p { prefHelpLongEquals = True }
helpShowGlobals :: PrefsMod
helpShowGlobals :: PrefsMod
helpShowGlobals = (ParserPrefs -> ParserPrefs) -> PrefsMod
PrefsMod ((ParserPrefs -> ParserPrefs) -> PrefsMod)
-> (ParserPrefs -> ParserPrefs) -> PrefsMod
forall a b. (a -> b) -> a -> b
$ \ParserPrefs
p -> ParserPrefs
p { prefHelpShowGlobal = True }
helpIndent :: Int -> PrefsMod
helpIndent :: Int -> PrefsMod
helpIndent Int
w = (ParserPrefs -> ParserPrefs) -> PrefsMod
PrefsMod ((ParserPrefs -> ParserPrefs) -> PrefsMod)
-> (ParserPrefs -> ParserPrefs) -> PrefsMod
forall a b. (a -> b) -> a -> b
$ \ParserPrefs
p -> ParserPrefs
p { prefTabulateFill = w }
prefs :: PrefsMod -> ParserPrefs
prefs :: PrefsMod -> ParserPrefs
prefs PrefsMod
m = PrefsMod -> ParserPrefs -> ParserPrefs
applyPrefsMod PrefsMod
m ParserPrefs
base
where
base :: ParserPrefs
base = ParserPrefs
{ prefMultiSuffix :: String
prefMultiSuffix = String
""
, prefDisambiguate :: Bool
prefDisambiguate = Bool
False
, prefShowHelpOnError :: Bool
prefShowHelpOnError = Bool
False
, prefShowHelpOnEmpty :: Bool
prefShowHelpOnEmpty = Bool
False
, prefBacktrack :: Backtracking
prefBacktrack = Backtracking
Backtrack
, prefColumns :: Int
prefColumns = Int
80
, prefHelpLongEquals :: Bool
prefHelpLongEquals = Bool
False
, prefHelpShowGlobal :: Bool
prefHelpShowGlobal = Bool
False
, prefTabulateFill :: Int
prefTabulateFill = Int
24 }
idm :: Monoid m => m
idm :: forall a. Monoid a => a
idm = m
forall a. Monoid a => a
mempty
defaultPrefs :: ParserPrefs
defaultPrefs :: ParserPrefs
defaultPrefs = PrefsMod -> ParserPrefs
prefs PrefsMod
forall a. Monoid a => a
idm