{-# 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::OptDescStyle->Optionra->StringoptDescstyleopt=letns=optionNames$opt^.optMainmv=opt^.optMetaVardescs=mapshowOption(sortns)desc'=intercalate(descSepstyle)descs<+>mvrendertext|not(opt^.optShow)&&not(descHiddenstyle)=""|nulltext||not(descSurroundstyle)=text|isJust(opt^.optDefault)="["++text++"]"|null(drop1descs)=text|otherwise="("++text++")"inrenderdesc'-- | Generate descriptions for commands.cmdDesc::Parsera->StringcmdDesc=intercalate"\n".filter(not.null).mapParserdescwheredescopt|CmdReadercmdsp<-opt^.optMain=tabulate[(cmd,d)|cmd<-cmds,d<-maybeToList.fmap(getLinfoProgDesc)$pcmd]|otherwise=""-- | Generate a brief help text for a parser.briefDesc::Parsera->StringbriefDesc=foldr(<+>)"".mapParser(optDescstyle)wherestyle=OptDescStyle{descSep="|",descHidden=False,descSurround=True}-- | Generate a full help text for a parser.fullDesc::Parsera->StringfullDesc=tabulate.catMaybes.mapParserdocwheredocopt|nulln=Nothing|nullh=Nothing|otherwise=Just(n,h)wheren=optDescstyleopth=opt^.optHelpstyle=OptDescStyle{descSep=",",descHidden=True,descSurround=False}-- | Generate the help text for a program.parserHelpText::ParserInfoa->StringparserHelpTextpinfo=unlines$nn[pinfo^.infoHeader]++[" "++line|line<-nn[pinfo^.infoProgDesc]]++[line|desc<-nn[fullDescp],line<-["","Common options:",desc],pinfo^.infoFullDesc]++[line|desc<-nn[cmdDescp],line<-["","Available commands:",desc],pinfo^.infoFullDesc]++[line|footer<-nn[pinfo^.infoFooter],line<-["",footer]]wherenn=filter(not.null)p=pinfo^.infoParser