{-# 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 = forall a. (String -> Either String a) -> ReadM a
eitherReader forall a b. (a -> b) -> a -> b
$ \String
arg -> case forall a. Read a => ReadS a
reads String
arg of
[(a
r, String
"")] -> forall (m :: * -> *) a. Monad m => a -> m a
return a
r
[(a, String)]
_ -> forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ String
"cannot parse value `" forall a. [a] -> [a] -> [a]
++ String
arg forall a. [a] -> [a] -> [a]
++ String
"'"
str :: IsString s => ReadM s
str :: forall s. IsString s => ReadM s
str = forall a. IsString a => String -> a
fromString 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 forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a. String -> ReadM a
readerError forall (m :: * -> *) a. Monad m => a -> m a
return 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
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a. String -> ReadM a
readerError forall a b. (a -> b) -> a -> b
$ String
"cannot parse value `" forall a. [a] -> [a] -> [a]
++ String
arg forall a. [a] -> [a] -> [a]
++ String
"'") forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Maybe a
f forall a b. (a -> b) -> a -> b
$ String
arg
disabled :: ReadM a
disabled :: forall a. ReadM a
disabled = 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 = forall (f :: * -> *) a. (f a -> f a) -> Mod f a
fieldMod forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. HasName f => OptName -> f a -> f a
name 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 = forall (f :: * -> *) a. (f a -> f a) -> Mod f a
fieldMod forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. HasName f => OptName -> f a -> f a
name 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 = forall (f :: * -> *) a.
(f a -> f a)
-> DefaultProp a -> (OptProperties -> OptProperties) -> Mod f a
Mod forall a. a -> a
id (forall a. Maybe a -> Maybe (a -> String) -> DefaultProp a
DefaultProp (forall a. a -> Maybe a
Just a
x) forall a. Maybe a
Nothing) forall a. a -> a
id
showDefaultWith :: (a -> String) -> Mod f a
showDefaultWith :: forall a (f :: * -> *). (a -> String) -> Mod f a
showDefaultWith a -> String
s = forall (f :: * -> *) a.
(f a -> f a)
-> DefaultProp a -> (OptProperties -> OptProperties) -> Mod f a
Mod forall a. a -> a
id (forall a. Maybe a -> Maybe (a -> String) -> DefaultProp a
DefaultProp forall a. Maybe a
Nothing (forall a. a -> Maybe a
Just a -> String
s)) forall a. a -> a
id
showDefault :: Show a => Mod f a
showDefault :: forall a (f :: * -> *). Show a => Mod f a
showDefault = forall a (f :: * -> *). (a -> String) -> Mod f a
showDefaultWith forall a. Show a => a -> String
show
help :: String -> Mod f a
help :: forall (f :: * -> *) a. String -> Mod f a
help String
s = forall (f :: * -> *) a. (OptProperties -> OptProperties) -> Mod f a
optionMod 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 :: forall (f :: * -> *) a. Maybe Doc -> Mod f a
helpDoc Maybe Doc
doc = forall (f :: * -> *) a. (OptProperties -> OptProperties) -> Mod f a
optionMod forall a b. (a -> b) -> a -> b
$ \OptProperties
p -> OptProperties
p { propHelp :: Chunk Doc
propHelp = forall a. Maybe a -> Chunk a
Chunk Maybe Doc
doc }
noArgError :: ParseError -> Mod OptionFields a
noArgError :: forall a. ParseError -> Mod OptionFields a
noArgError ParseError
e = forall (f :: * -> *) a. (f a -> f a) -> Mod f a
fieldMod forall a b. (a -> b) -> a -> b
$ \OptionFields a
p -> OptionFields a
p { optNoArgError :: String -> ParseError
optNoArgError = forall a b. a -> b -> a
const ParseError
e }
metavar :: HasMetavar f => String -> Mod f a
metavar :: forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
var = forall (f :: * -> *) a. (OptProperties -> OptProperties) -> Mod f a
optionMod forall a b. (a -> b) -> a -> b
$ \OptProperties
p -> OptProperties
p { propMetaVar :: String
propMetaVar = String
var }
hidden :: Mod f a
hidden :: forall (f :: * -> *) a. Mod f a
hidden = forall (f :: * -> *) a. (OptProperties -> OptProperties) -> Mod f a
optionMod forall a b. (a -> b) -> a -> b
$ \OptProperties
p ->
OptProperties
p { propVisibility :: OptVisibility
propVisibility = forall a. Ord a => a -> a -> a
min OptVisibility
Hidden (OptProperties -> OptVisibility
propVisibility OptProperties
p) }
style :: ( Doc -> Doc ) -> Mod f a
style :: forall (f :: * -> *) a. (Doc -> Doc) -> Mod f a
style Doc -> Doc
x = forall (f :: * -> *) a. (OptProperties -> OptProperties) -> Mod f a
optionMod forall a b. (a -> b) -> a -> b
$ \OptProperties
p ->
OptProperties
p { propDescMod :: Maybe (Doc -> Doc)
propDescMod = forall a. a -> Maybe a
Just Doc -> Doc
x }
command :: String -> ParserInfo a -> Mod CommandFields a
command :: forall a. String -> ParserInfo a -> Mod CommandFields a
command String
cmd ParserInfo a
pinfo = forall (f :: * -> *) a. (f a -> f a) -> Mod f a
fieldMod forall a b. (a -> b) -> a -> b
$ \CommandFields a
p ->
CommandFields a
p { cmdCommands :: [(String, ParserInfo a)]
cmdCommands = (String
cmd, ParserInfo a
pinfo) forall a. a -> [a] -> [a]
: forall a. CommandFields a -> [(String, ParserInfo a)]
cmdCommands CommandFields a
p }
commandGroup :: String -> Mod CommandFields a
commandGroup :: forall a. String -> Mod CommandFields a
commandGroup String
g = forall (f :: * -> *) a. (f a -> f a) -> Mod f a
fieldMod forall a b. (a -> b) -> a -> b
$ \CommandFields a
p ->
CommandFields a
p { cmdGroup :: Maybe String
cmdGroup = forall a. a -> Maybe a
Just String
g }
completeWith :: HasCompleter f => [String] -> Mod f a
completeWith :: forall (f :: * -> *) a. HasCompleter f => [String] -> Mod f a
completeWith = forall (f :: * -> *) a. HasCompleter f => Completer -> Mod f a
completer 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 = forall (f :: * -> *) a. HasCompleter f => Completer -> Mod f a
completer 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 = forall (f :: * -> *) a. (f a -> f a) -> Mod f a
fieldMod forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a.
HasCompleter f =>
(Completer -> Completer) -> f a -> f a
modCompleter (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 = 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 = forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"COMMAND" forall a. Monoid a => a -> a -> a
`mappend` Mod CommandFields a
m
(Maybe String
groupName, [String]
cmds, String -> Maybe (ParserInfo a)
subs) = forall a.
Mod CommandFields a
-> (Maybe String, [String], String -> Maybe (ParserInfo a))
mkCommand Mod CommandFields a
m
rdr :: OptReader a
rdr = 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 :: forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ReadM a
p Mod ArgumentFields a
m = forall a.
DefaultProp a
-> (OptProperties -> OptProperties) -> OptReader a -> Parser a
mkParser DefaultProp a
d OptProperties -> OptProperties
g (forall a. CReader a -> OptReader a
ArgReader CReader a
rdr)
where
(Mod ArgumentFields a -> ArgumentFields a
f DefaultProp a
d OptProperties -> OptProperties
g) = forall (f :: * -> *) a. Mod f a
noGlobal forall a. Monoid a => a -> a -> a
`mappend` Mod ArgumentFields a
m
ArgumentFields Completer
compl = ArgumentFields a -> ArgumentFields a
f (forall a. Completer -> ArgumentFields a
ArgumentFields forall a. Monoid a => a
mempty)
rdr :: CReader a
rdr = 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 = forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument 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 = forall a. a -> Mod FlagFields a -> Parser a
flag' a
actv Mod FlagFields a
m forall (f :: * -> *) a. Alternative f => f a -> f a -> f 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) = 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 (forall a. [OptName] -> a -> FlagFields a
FlagFields [] a
actv)
in forall a. [OptName] -> a -> OptReader a
FlagReader (forall a. FlagFields a -> [OptName]
flagNames FlagFields a
fields)
(forall a. FlagFields a -> a
flagActive FlagFields a
fields)
switch :: Mod FlagFields Bool -> Parser Bool
switch :: Mod FlagFields Bool -> Parser Bool
switch = 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 = forall a. ReadM a -> Mod OptionFields a -> Parser a
option (forall a. ParseError -> ReadM a
readerAbort ParseError
err) forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Monoid a => a -> a -> a
`mappend` Mod OptionFields (a -> a)
m) forall a b. (a -> b) -> a -> b
$ forall a. Monoid a => [a] -> a
mconcat
[ forall a. ParseError -> Mod OptionFields a
noArgError ParseError
err
, forall (f :: * -> *) a. HasValue f => a -> Mod f a
value forall a. a -> a
id
, 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 = forall a.
ParseError -> Mod OptionFields (a -> a) -> Parser (a -> a)
abortOption 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 = forall a. ReadM a -> Mod OptionFields a -> Parser a
option 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 = 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 = forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"ARG" forall a. Monoid a => a -> a -> a
`mappend` Mod OptionFields a
m
fields :: OptionFields a
fields = OptionFields a -> OptionFields a
f (forall a.
[OptName] -> Completer -> (String -> ParseError) -> OptionFields a
OptionFields [] forall a. Monoid a => a
mempty String -> ParseError
ExpectsArgError)
crdr :: CReader a
crdr = forall a. Completer -> ReadM a -> CReader a
CReader (forall a. OptionFields a -> Completer
optCompleter OptionFields a
fields) ReadM a
r
rdr :: OptReader a
rdr = forall a.
[OptName] -> CReader a -> (String -> ParseError) -> OptReader a
OptReader (forall a. OptionFields a -> [OptName]
optNames OptionFields a
fields) CReader a
crdr (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 = forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod forall a. a -> a
id
mappend :: InfoMod a -> InfoMod a -> InfoMod a
mappend = forall a. Semigroup a => a -> a -> a
(<>)
instance Semigroup (InfoMod a) where
InfoMod a
m1 <> :: InfoMod a -> InfoMod a -> InfoMod a
<> InfoMod a
m2 = forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod forall a b. (a -> b) -> a -> b
$ forall a. InfoMod a -> ParserInfo a -> ParserInfo a
applyInfoMod InfoMod a
m2 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. InfoMod a -> ParserInfo a -> ParserInfo a
applyInfoMod InfoMod a
m1
fullDesc :: InfoMod a
fullDesc :: forall a. InfoMod a
fullDesc = forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod forall a b. (a -> b) -> a -> b
$ \ParserInfo a
i -> ParserInfo a
i { infoFullDesc :: Bool
infoFullDesc = Bool
True }
briefDesc :: InfoMod a
briefDesc :: forall a. InfoMod a
briefDesc = forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod forall a b. (a -> b) -> a -> b
$ \ParserInfo a
i -> ParserInfo a
i { infoFullDesc :: Bool
infoFullDesc = Bool
False }
header :: String -> InfoMod a
String
s = forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod 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 = forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod forall a b. (a -> b) -> a -> b
$ \ParserInfo a
i -> ParserInfo a
i { infoHeader :: Chunk Doc
infoHeader = forall a. Maybe a -> Chunk a
Chunk Maybe Doc
doc }
footer :: String -> InfoMod a
String
s = forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod 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 = forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod forall a b. (a -> b) -> a -> b
$ \ParserInfo a
i -> ParserInfo a
i { infoFooter :: Chunk Doc
infoFooter = forall a. Maybe a -> Chunk a
Chunk Maybe Doc
doc }
progDesc :: String -> InfoMod a
progDesc :: forall a. String -> InfoMod a
progDesc String
s = forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod 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 :: forall a. Maybe Doc -> InfoMod a
progDescDoc Maybe Doc
doc = forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod forall a b. (a -> b) -> a -> b
$ \ParserInfo a
i -> ParserInfo a
i { infoProgDesc :: Chunk Doc
infoProgDesc = forall a. Maybe a -> Chunk a
Chunk Maybe Doc
doc }
failureCode :: Int -> InfoMod a
failureCode :: forall a. Int -> InfoMod a
failureCode Int
n = forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod forall a b. (a -> b) -> a -> b
$ \ParserInfo a
i -> ParserInfo a
i { infoFailureCode :: Int
infoFailureCode = Int
n }
noIntersperse :: InfoMod a
noIntersperse :: forall a. InfoMod a
noIntersperse = forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod forall a b. (a -> b) -> a -> b
$ \ParserInfo a
p -> ParserInfo a
p { infoPolicy :: ArgPolicy
infoPolicy = ArgPolicy
NoIntersperse }
forwardOptions :: InfoMod a
forwardOptions :: forall a. InfoMod a
forwardOptions = forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod forall a b. (a -> b) -> a -> b
$ \ParserInfo a
p -> ParserInfo a
p { infoPolicy :: ArgPolicy
infoPolicy = ArgPolicy
ForwardOptions }
allPositional :: InfoMod a
allPositional :: forall a. InfoMod a
allPositional = forall a. (ParserInfo a -> ParserInfo a) -> InfoMod a
InfoMod 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 :: forall a. Parser a -> InfoMod a -> ParserInfo a
info Parser a
parser InfoMod a
m = 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 = forall a. Monoid a => a
mempty
, infoHeader :: Chunk Doc
infoHeader = forall a. Monoid a => a
mempty
, infoFooter :: Chunk Doc
infoFooter = 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 forall a. a -> a
id
mappend :: PrefsMod -> PrefsMod -> PrefsMod
mappend = forall a. Semigroup a => a -> a -> a
(<>)
instance Semigroup PrefsMod where
PrefsMod
m1 <> :: PrefsMod -> PrefsMod -> PrefsMod
<> PrefsMod
m2 = (ParserPrefs -> ParserPrefs) -> PrefsMod
PrefsMod forall a b. (a -> b) -> a -> b
$ PrefsMod -> ParserPrefs -> ParserPrefs
applyPrefsMod PrefsMod
m2 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 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 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 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 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 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 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 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 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 forall a b. (a -> b) -> a -> b
$ \ParserPrefs
p -> ParserPrefs
p { prefHelpShowGlobal :: Bool
prefHelpShowGlobal = Bool
True }
helpIndent :: Int -> PrefsMod
helpIndent :: Int -> PrefsMod
helpIndent Int
w = (ParserPrefs -> ParserPrefs) -> PrefsMod
PrefsMod forall a b. (a -> b) -> a -> b
$ \ParserPrefs
p -> ParserPrefs
p { prefTabulateFill :: Int
prefTabulateFill = Int
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 = forall a. Monoid a => a
mempty
defaultPrefs :: ParserPrefs
defaultPrefs :: ParserPrefs
defaultPrefs = PrefsMod -> ParserPrefs
prefs forall a. Monoid a => a
idm