{-# 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,
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 :: 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 (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 :: 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 :: (String -> Either String a) -> ReadM a
eitherReader String -> Either String a
f = ReadM String
readerAsk ReadM String -> (String -> ReadM a) -> ReadM a
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 (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 :: (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 (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 :: ReadM a
disabled = String -> ReadM a
forall a. String -> ReadM a
readerError String
"disabled option"
short :: HasName f => Char -> Mod f a
short :: 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 (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 :: 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 (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 :: 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 :: (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 :: 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 :: 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 :: Chunk Doc
propHelp = String -> Chunk Doc
paragraph String
s }
helpDoc :: Maybe Doc -> Mod f a
helpDoc :: 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
propHelp = Maybe Doc -> Chunk Doc
forall a. Maybe a -> Chunk a
Chunk Maybe Doc
doc }
noArgError :: ParseError -> Mod OptionFields a
noArgError :: 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 :: String -> ParseError
optNoArgError = ParseError -> String -> ParseError
forall a b. a -> b -> a
const ParseError
e }
metavar :: HasMetavar f => String -> Mod f a
metavar :: 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 :: String
propMetaVar = String
var }
hidden :: Mod f a
hidden :: 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 :: OptVisibility
propVisibility = OptVisibility -> OptVisibility -> OptVisibility
forall a. Ord a => a -> a -> a
min OptVisibility
Hidden (OptProperties -> OptVisibility
propVisibility OptProperties
p) }
style :: ( Doc -> Doc ) -> Mod f a
style :: (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 :: Maybe (Doc -> Doc)
propDescMod = (Doc -> Doc) -> Maybe (Doc -> Doc)
forall a. a -> Maybe a
Just Doc -> Doc
x }
command :: String -> ParserInfo a -> Mod CommandFields a
command :: 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 :: [(String, ParserInfo a)]
cmdCommands = (String
cmd, ParserInfo a
pinfo) (String, ParserInfo a)
-> [(String, ParserInfo a)] -> [(String, ParserInfo a)]
forall a. a -> [a] -> [a]
: CommandFields a -> [(String, ParserInfo a)]
forall a. CommandFields a -> [(String, ParserInfo a)]
cmdCommands CommandFields a
p }
commandGroup :: String -> Mod CommandFields a
commandGroup :: 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 :: Maybe String
cmdGroup = String -> Maybe String
forall a. a -> Maybe a
Just String
g }
completeWith :: HasCompleter f => [String] -> Mod f a
completeWith :: [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 :: 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 :: 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 (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 :: 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]
cmds, String -> Maybe (ParserInfo a)
subs) = Mod CommandFields a
-> (Maybe String, [String], String -> Maybe (ParserInfo a))
forall a.
Mod CommandFields a
-> (Maybe String, [String], String -> Maybe (ParserInfo a))
mkCommand Mod CommandFields a
m
rdr :: OptReader a
rdr = Maybe String
-> [String] -> (String -> Maybe (ParserInfo a)) -> OptReader a
forall a.
Maybe String
-> [String] -> (String -> Maybe (ParserInfo a)) -> OptReader a
CmdReader Maybe String
groupName [String]
cmds String -> Maybe (ParserInfo a)
subs
argument :: ReadM a -> Mod ArgumentFields a -> Parser a
argument :: 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 :: 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 :: 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 (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
defv
flag' :: a
-> Mod FlagFields a
-> Parser a
flag' :: 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 :: 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 :: 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 :: 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 :: 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
{ 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 :: 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 :: Bool
infoFullDesc = Bool
True }
briefDesc :: InfoMod a
briefDesc :: 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 :: Bool
infoFullDesc = Bool
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 :: Chunk Doc
infoHeader = String -> Chunk Doc
paragraph String
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
infoHeader = Maybe Doc -> Chunk Doc
forall a. Maybe a -> Chunk a
Chunk Maybe Doc
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 :: Chunk Doc
infoFooter = String -> Chunk Doc
paragraph String
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
infoFooter = Maybe Doc -> Chunk Doc
forall a. Maybe a -> Chunk a
Chunk Maybe Doc
doc }
progDesc :: String -> InfoMod a
progDesc :: 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 :: Chunk Doc
infoProgDesc = String -> Chunk Doc
paragraph String
s }
progDescDoc :: Maybe Doc -> InfoMod a
progDescDoc :: 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
infoProgDesc = Maybe Doc -> Chunk Doc
forall a. Maybe a -> Chunk a
Chunk Maybe Doc
doc }
failureCode :: Int -> InfoMod a
failureCode :: 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 :: Int
infoFailureCode = Int
n }
noIntersperse :: InfoMod a
noIntersperse :: 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 :: ArgPolicy
infoPolicy = ArgPolicy
NoIntersperse }
forwardOptions :: InfoMod a
forwardOptions :: 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 :: ArgPolicy
infoPolicy = ArgPolicy
ForwardOptions }
allPositional :: InfoMod a
allPositional :: 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 :: ArgPolicy
infoPolicy = ArgPolicy
AllPositionals }
info :: Parser a -> InfoMod a -> ParserInfo a
info :: 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 :: forall a.
Parser a
-> Bool
-> Chunk Doc
-> Chunk Doc
-> Chunk Doc
-> Int
-> ArgPolicy
-> ParserInfo a
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 :: String
prefMultiSuffix = String
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 :: Bool
prefDisambiguate = Bool
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 :: Bool
prefShowHelpOnError = Bool
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 :: Bool
prefShowHelpOnEmpty = Bool
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 :: Backtracking
prefBacktrack = Backtracking
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 :: Backtracking
prefBacktrack = Backtracking
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 :: Int
prefColumns = Int
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 :: Bool
prefHelpLongEquals = Bool
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 :: Bool
prefHelpShowGlobal = Bool
True}
prefs :: PrefsMod -> ParserPrefs
prefs :: PrefsMod -> ParserPrefs
prefs PrefsMod
m = PrefsMod -> ParserPrefs -> ParserPrefs
applyPrefsMod PrefsMod
m ParserPrefs
base
where
base :: ParserPrefs
base = ParserPrefs :: String
-> Bool
-> Bool
-> Bool
-> Backtracking
-> Int
-> Bool
-> Bool
-> ParserPrefs
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 }
idm :: Monoid m => m
idm :: m
idm = m
forall a. Monoid a => a
mempty
defaultPrefs :: ParserPrefs
defaultPrefs :: ParserPrefs
defaultPrefs = PrefsMod -> ParserPrefs
prefs PrefsMod
forall a. Monoid a => a
idm