{-# LANGUAGE PatternGuards #-}moduleOptions.Applicative.Help(cmdDesc,briefDesc,fullDesc,parserHelpText,)whereimportData.Lens.CommonimportData.ListimportData.MaybeimportOptions.Applicative.CommonimportOptions.Applicative.TypesimportOptions.Applicative.UtilsshowOption::OptName->StringshowOption(OptLongn)="--"++nshowOption(OptShortn)='-':[n]-- | Style for rendering an option.dataOptDescStyle=OptDescStyle{descSep::String,descHidden::Bool,descSurround::Bool}-- | Generate description for a single option.optDesc::ParserPrefs->OptDescStyle->OptHelpInfo->Optiona->StringoptDescpprefsstyleinfoopt=letns=optionNames$opt^.optMainmv=opt^.optMetaVardescs=mapshowOption(sortns)desc'=intercalate(descSepstyle)descs<+>mvshow_opt|opt^.optVisibility==Hidden=descHiddenstyle|otherwise=opt^.optVisibility==Visiblesuffix|hinfoMultiinfo=pprefs^.prefMultiSuffix|otherwise=""rendertext|notshow_opt=""|nulltext||not(descSurroundstyle)=text++suffix|hinfoDefaultinfo="["++text++"]"++suffix|null(drop1descs)=text++suffix|otherwise="("++text++")"++suffixinrenderdesc'-- | Generate descriptions for commands.cmdDesc::Parsera->[String]cmdDesc=concat.mapParserdescwheredesc_opt|CmdReadercmdsp<-opt^.optMain=tabulate[(cmd,d)|cmd<-cmds,d<-maybeToList.fmap(getLinfoProgDesc)$pcmd]|otherwise=[]-- | Generate a brief help text for a parser.briefDesc::ParserPrefs->Parsera->StringbriefDescpprefs=foldr(<+>)"".mapParser(optDescpprefsstyle)wherestyle=OptDescStyle{descSep="|",descHidden=False,descSurround=True}-- | Generate a full help text for a parser.fullDesc::ParserPrefs->Parsera->[String]fullDescpprefs=tabulate.catMaybes.mapParserdocwheredocinfoopt|nulln=Nothing|nullh=Nothing|otherwise=Just(n,h)wheren=optDescpprefsstyleinfoopth=opt^.optHelpstyle=OptDescStyle{descSep=",",descHidden=True,descSurround=False}-- | Generate the help text for a program.parserHelpText::ParserPrefs->ParserInfoa->StringparserHelpTextpprefspinfo=unlines$nn[pinfo^.infoHeader]++[" "++line|line<-nn[pinfo^.infoProgDesc]]++[line|letopts=fullDescpprefsp,not(nullopts),line<-["","Common options:"]++opts,pinfo^.infoFullDesc]++[line|letcmds=cmdDescp,not(nullcmds),line<-["","Available commands:"]++cmds,pinfo^.infoFullDesc]++[line|footer<-nn[pinfo^.infoFooter],line<-["",footer]]wherenn=filter(not.null)p=pinfo^.infoParser