{-# LANGUAGE CPP #-}moduleOptions.Applicative.Builder(-- * Parser builders---- | This module contains utility functions and combinators to create parsers-- for individual options.---- Each parser builder takes an option modifier. A modifier can be created by-- composing the basic modifiers provided by this module using the 'Monoid'-- operations 'mempty' and 'mappend', or their aliases 'idm' and '<>'.---- For example:---- > out = strOption-- > ( long "output"-- > <> short 'o'-- > <> metavar "FILENAME" )---- creates a parser for an option called \"output\".subparser,argument,arguments,arguments1,flag,flag',switch,nullOption,abortOption,infoOption,strOption,option,-- * Modifiersshort,long,help,value,showDefaultWith,showDefault,metavar,reader,eitherReader,noArgError,ParseError(..),hidden,internal,command,completeWith,action,completer,idm,(&),#if __GLASGOW_HASKELL__ > 702(<>),#endifmappend,-- * Readers---- | A collection of basic 'Option' readers.auto,str,disabled,readerAbort,readerError,-- * Builder for 'ParserInfo'InfoMod,fullDesc,briefDesc,header,progDesc,footer,failureCode,info,-- * Builder for 'ParserPrefs'PrefsMod,multiSuffix,disambiguate,showHelpOnError,noBacktrack,noIntersperse,prefs,-- * TypesMod,ReadM,OptionFields,FlagFields,ArgumentFields,CommandFields)whereimportControl.Applicative(pure,(<|>),many,some)importData.Monoid(Monoid(..)#if __GLASGOW_HASKELL__ > 702,(<>)#endif)importOptions.Applicative.Builder.CompleterimportOptions.Applicative.Builder.InternalimportOptions.Applicative.CommonimportOptions.Applicative.Types-- readers ---- | 'Option' reader based on the 'Read' type class.auto::Monadm=>Reada=>String->maautoarg=casereadsargof[(r,"")]->returnr_->fail$"cannot parse value `"++arg++"'"-- | String 'Option' reader.str::Monadm=>String->mStringstr=return-- | Null 'Option' reader. All arguments will fail validation.disabled::Monadm=>String->madisabled=const.fail$"disabled option"-- modifiers ---- | Specify a short name for an option.short::HasNamef=>Char->Modfashort=fieldMod.name.OptShort-- | Specify a long name for an option.long::HasNamef=>String->Modfalong=fieldMod.name.OptLong-- | Specify a default value for an option.value::a->Modfavaluex=Modid(DefaultProp(Justx)Nothing)id-- | Specify a function to show the default value for an option.showDefaultWith::(a->String)->ModfashowDefaultWiths=Modid(DefaultPropNothing(Justs))id-- | Show the default value for this option using its 'Show' instance.showDefault::Showa=>ModfashowDefault=showDefaultWithshow-- | Specify the help text for an option.help::String->Modfahelps=optionMod$\p->p{propHelp=s}-- | Specify the 'Option' reader.reader::(String->ReadMa)->ModOptionFieldsareaderf=fieldMod$\p->p{optReader=f}-- | Specify the 'Option' reader as a function in the 'Either' monad.eitherReader::(String->EitherStringa)->ModOptionFieldsaeitherReaderf=reader(eitherreaderErrorreturn.f)-- | Specify the error to display when no argument is provided to this option.noArgError::ParseError->ModOptionFieldsanoArgErrore=fieldMod$\p->p{optNoArgError=e}-- | Specify the metavariable.metavar::String->Modfametavarvar=optionMod$\p->p{propMetaVar=var}-- | Hide this option from the brief description.hidden::Modfahidden=optionMod$\p->p{propVisibility=minHidden(propVisibilityp)}-- | Add a command to a subparser option.command::String->ParserInfoa->ModCommandFieldsacommandcmdpinfo=fieldMod$\p->p{cmdCommands=(cmd,pinfo):cmdCommandsp}-- | Add a list of possible completion values.completeWith::HasCompleterf=>[String]->ModfacompleteWithxs=completer(listCompleterxs)-- | 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.action::HasCompleterf=>String->Modfaactionact=completer(bashCompleteract)-- | 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.completer::HasCompleterf=>Completer->Modfacompleterf=fieldMod$modCompleter(`mappend`f)-- parsers ---- | Builder for a command parser. The 'command' modifier can be used to-- specify individual commands.subparser::ModCommandFieldsa->Parserasubparserm=mkParserdgrdrwhereMod_dg=m`mappend`metavar"COMMAND"rdr=uncurryCmdReader(mkCommandm)-- | Builder for an argument parser.argument::(String->Maybea)->ModArgumentFieldsa->Parseraargumentp(Modfdg)=mkParserdg(ArgReaderrdr)whereArgumentFieldscompl=f(ArgumentFieldsmempty)rdr=CReadercomplp-- | Builder for an argument list parser. All arguments are collected and-- returned as a list.arguments::(String->Maybea)->ModArgumentFieldsa->Parser[a]argumentsrm=many(argumentrm)-- | Like `arguments`, but require at least one argument.arguments1::(String->Maybea)->ModArgumentFieldsa->Parser[a]arguments1rm=some(argumentrm)-- | 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.flag::a-- ^ default value->a-- ^ active value->ModFlagFieldsa-- ^ option modifier->Parseraflagdefvactvm=flag'actvm<|>puredefv-- | 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.flag'::a-- ^ active value->ModFlagFieldsa-- ^ option modifier->Parseraflag'actv(Modfdg)=mkParserdgrdrwhererdr=letfields=f(FlagFields[]actv)inFlagReader(flagNamesfields)(flagActivefields)-- | Builder for a boolean flag.---- > switch = flag False Trueswitch::ModFlagFieldsBool->ParserBoolswitch=flagFalseTrue-- | Builder for an option with a null reader. A non-trivial reader can be-- added using the 'reader' modifier.nullOption::ModOptionFieldsa->ParseranullOptionm=mkParserdgrdrwhereModfdg=metavar"ARG"`mappend`mfields=f(OptionFields[]memptydisabled(ErrorMsg""))crdr=CReader(optCompleterfields)(optReaderfields)rdr=OptReader(optNamesfields)crdr(optNoArgErrorfields)-- | 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.abortOption::ParseError->ModOptionFields(a->a)->Parser(a->a)abortOptionerrm=nullOption.(<>m)$mconcat[reader(const(ReadM(Lefterr))),noArgErrorerr,valueid,metavar"",hidden]-- | An option that always fails and displays a message.infoOption::String->ModOptionFields(a->a)->Parser(a->a)infoOption=abortOption.InfoMsg-- | Builder for an option taking a 'String' argument.strOption::ModOptionFieldsString->ParserStringstrOptionm=nullOption$readerstr`mappend`m-- | Builder for an option using the 'auto' reader.option::Reada=>ModOptionFieldsa->Parseraoptionm=nullOption$readerauto`mappend`m-- | Modifier for 'ParserInfo'.newtypeInfoModa=InfoMod{applyInfoMod::ParserInfoa->ParserInfoa}instanceMonoid(InfoModa)wheremempty=InfoModidmappendm1m2=InfoMod$applyInfoModm2.applyInfoModm1-- | Show a full description in the help text of this parser.fullDesc::InfoModafullDesc=InfoMod$\i->i{infoFullDesc=True}-- | Only show a brief description in the help text of this parser.briefDesc::InfoModabriefDesc=InfoMod$\i->i{infoFullDesc=False}-- | Specify a header for this parser.header::String->InfoModaheaders=InfoMod$\i->i{infoHeader=s}-- | Specify a footer for this parser.footer::String->InfoModafooters=InfoMod$\i->i{infoFooter=s}-- | Specify a short program description.progDesc::String->InfoModaprogDescs=InfoMod$\i->i{infoProgDesc=s}-- | Specify an exit code if a parse error occurs.failureCode::Int->InfoModafailureCoden=InfoMod$\i->i{infoFailureCode=n}-- | Create a 'ParserInfo' given a 'Parser' and a modifier.info::Parsera->InfoModa->ParserInfoainfoparserm=applyInfoModmbasewherebase=ParserInfo{infoParser=parser,infoFullDesc=True,infoProgDesc="",infoHeader="",infoFooter="",infoFailureCode=1}newtypePrefsMod=PrefsMod{applyPrefsMod::ParserPrefs->ParserPrefs}instanceMonoidPrefsModwheremempty=PrefsModidmappendm1m2=PrefsMod$applyPrefsModm2.applyPrefsModm1multiSuffix::String->PrefsModmultiSuffixs=PrefsMod$\p->p{prefMultiSuffix=s}disambiguate::PrefsModdisambiguate=PrefsMod$\p->p{prefDisambiguate=True}showHelpOnError::PrefsModshowHelpOnError=PrefsMod$\p->p{prefShowHelpOnError=True}noBacktrack::PrefsModnoBacktrack=PrefsMod$\p->p{prefBacktrack=False}noIntersperse::PrefsModnoIntersperse=PrefsMod$\p->p{prefIntersperse=False}prefs::PrefsMod->ParserPrefsprefsm=applyPrefsModmbasewherebase=ParserPrefs{prefMultiSuffix="",prefDisambiguate=False,prefShowHelpOnError=False,prefBacktrack=True,prefIntersperse=True}-- convenience shortcuts-- | Trivial option modifier.idm::Monoidm=>midm=mempty-- | Compose modifiers.{-# DEPRECATED (&) "Use (<>) instead" #-}(&)::Monoidm=>m->m->m(&)=mappend