------------------------------------------------------------------------------- |-- Module : Haddock.Options-- Copyright : (c) Simon Marlow 2003-2006,-- David Waern 2006-2009-- License : BSD-like---- Maintainer : haddock@projects.haskell.org-- Stability : experimental-- Portability : portable---- Definition of the command line interface of Haddock.-----------------------------------------------------------------------------moduleHaddock.Options(parseHaddockOpts,Flag(..),getUsage,optTitle,outputDir,optContentsUrl,optIndexUrl,optCssFile,sourceUrls,wikiUrls,optDumpInterfaceFile,optLaTeXStyle,qualification,verbosity,ghcFlags,readIfaceArgs)whereimportData.MaybeimportDistribution.VerbosityimportHaddock.UtilsimportHaddock.TypesimportSystem.Console.GetOptimportqualifiedData.CharasChardataFlag=Flag_BuiltInThemes|Flag_CSSString-- | Flag_DocBook|Flag_ReadInterfaceString|Flag_DumpInterfaceString|Flag_HeadingString|Flag_Html|Flag_Hoogle|Flag_LibString|Flag_OutputDirFilePath|Flag_PrologueFilePath|Flag_SourceBaseURLString|Flag_SourceModuleURLString|Flag_SourceEntityURLString|Flag_WikiBaseURLString|Flag_WikiModuleURLString|Flag_WikiEntityURLString|Flag_LaTeX|Flag_LaTeXStyleString|Flag_Help|Flag_VerbosityString|Flag_Version|Flag_InterfaceVersion|Flag_UseContentsString|Flag_GenContents|Flag_UseIndexString|Flag_GenIndex|Flag_IgnoreAllExports|Flag_HideModuleString|Flag_OptGhcString|Flag_GhcLibDirString|Flag_GhcVersion|Flag_PrintGhcPath|Flag_PrintGhcLibDir|Flag_NoWarnings|Flag_UseUnicode|Flag_NoTmpCompDir|Flag_QualificationString|Flag_PrettyHtmlderiving(Eq)options::Bool->[OptDescrFlag]optionsbackwardsCompat=[Option['B'][](ReqArgFlag_GhcLibDir"DIR")"path to a GHC lib dir, to override the default path",Option['o']["odir"](ReqArgFlag_OutputDir"DIR")"directory in which to put the output files",Option['l']["lib"](ReqArgFlag_Lib"DIR")"location of Haddock's auxiliary files",Option['i']["read-interface"](ReqArgFlag_ReadInterface"FILE")"read an interface from FILE",Option['D']["dump-interface"](ReqArgFlag_DumpInterface"FILE")"write the resulting interface to FILE",-- Option ['S'] ["docbook"] (NoArg Flag_DocBook)-- "output in DocBook XML",Option['h']["html"](NoArgFlag_Html)"output in HTML (XHTML 1.0)",Option[]["latex"](NoArgFlag_LaTeX)"use experimental LaTeX rendering",Option[]["latex-style"](ReqArgFlag_LaTeXStyle"FILE")"provide your own LaTeX style in FILE",Option['U']["use-unicode"](NoArgFlag_UseUnicode)"use Unicode in HTML output",Option[]["hoogle"](NoArgFlag_Hoogle)"output for Hoogle",Option[]["source-base"](ReqArgFlag_SourceBaseURL"URL")"URL for a source code link on the contents\nand index pages",Option['s'](ifbackwardsCompatthen["source","source-module"]else["source-module"])(ReqArgFlag_SourceModuleURL"URL")"URL for a source code link for each module\n(using the %{FILE} or %{MODULE} vars)",Option[]["source-entity"](ReqArgFlag_SourceEntityURL"URL")"URL for a source code link for each entity\n(using the %{FILE}, %{MODULE}, %{NAME},\n%{KIND} or %{LINE} vars)",Option[]["comments-base"](ReqArgFlag_WikiBaseURL"URL")"URL for a comments link on the contents\nand index pages",Option[]["comments-module"](ReqArgFlag_WikiModuleURL"URL")"URL for a comments link for each module\n(using the %{MODULE} var)",Option[]["comments-entity"](ReqArgFlag_WikiEntityURL"URL")"URL for a comments link for each entity\n(using the %{FILE}, %{MODULE}, %{NAME},\n%{KIND} or %{LINE} vars)",Option['c']["css","theme"](ReqArgFlag_CSS"PATH")"the CSS file or theme directory to use for HTML output",Option[]["built-in-themes"](NoArgFlag_BuiltInThemes)"include all the built-in haddock themes",Option['p']["prologue"](ReqArgFlag_Prologue"FILE")"file containing prologue text",Option['t']["title"](ReqArgFlag_Heading"TITLE")"page heading",Option['q']["qual"](ReqArgFlag_Qualification"QUAL")"qualification of names, one of \n'none' (default), 'full', 'local'\n'relative' or 'aliased'",Option['?']["help"](NoArgFlag_Help)"display this help and exit",Option['V']["version"](NoArgFlag_Version)"output version information and exit",Option[]["interface-version"](NoArgFlag_InterfaceVersion)"output interface file version and exit",Option['v']["verbosity"](ReqArgFlag_Verbosity"VERBOSITY")"set verbosity level",Option[]["use-contents"](ReqArgFlag_UseContents"URL")"use a separately-generated HTML contents page",Option[]["gen-contents"](NoArgFlag_GenContents)"generate an HTML contents from specified\ninterfaces",Option[]["use-index"](ReqArgFlag_UseIndex"URL")"use a separately-generated HTML index",Option[]["gen-index"](NoArgFlag_GenIndex)"generate an HTML index from specified\ninterfaces",Option[]["ignore-all-exports"](NoArgFlag_IgnoreAllExports)"behave as if all modules have the\nignore-exports atribute",Option[]["hide"](ReqArgFlag_HideModule"MODULE")"behave as if MODULE has the hide attribute",Option[]["optghc"](ReqArgFlag_OptGhc"OPTION")"option to be forwarded to GHC",Option[]["ghc-version"](NoArgFlag_GhcVersion)"output GHC version in numeric format",Option[]["print-ghc-path"](NoArgFlag_PrintGhcPath)"output path to GHC binary",Option[]["print-ghc-libdir"](NoArgFlag_PrintGhcLibDir)"output GHC lib dir",Option['w']["no-warnings"](NoArgFlag_NoWarnings)"turn off all warnings",Option[]["no-tmp-comp-dir"](NoArgFlag_NoTmpCompDir)"do not re-direct compilation output to a temporary directory",Option[]["pretty-html"](NoArgFlag_PrettyHtml)"generate html with newlines and indenting (for use with --html)"]getUsage::IOStringgetUsage=doprog<-getProgramNamereturn$usageInfo(usageHeaderprog)(optionsFalse)whereusageHeader::String->StringusageHeaderprog="Usage: "++prog++" [OPTION...] file...\n"parseHaddockOpts::[String]->IO([Flag],[String])parseHaddockOptsparams=casegetOptPermute(optionsTrue)paramsof(flags,args,[])->return(flags,args)(_,_,errors)->dousage<-getUsagethrowE(concaterrors++usage)optTitle::[Flag]->MaybeStringoptTitleflags=case[str|Flag_Headingstr<-flags]of[]->Nothing(t:_)->JusttoutputDir::[Flag]->FilePathoutputDirflags=case[path|Flag_OutputDirpath<-flags]of[]->"."paths->lastpathsoptContentsUrl::[Flag]->MaybeStringoptContentsUrlflags=optLast[url|Flag_UseContentsurl<-flags]optIndexUrl::[Flag]->MaybeStringoptIndexUrlflags=optLast[url|Flag_UseIndexurl<-flags]optCssFile::[Flag]->MaybeFilePathoptCssFileflags=optLast[str|Flag_CSSstr<-flags]sourceUrls::[Flag]->(MaybeString,MaybeString,MaybeString)sourceUrlsflags=(listToMaybe[str|Flag_SourceBaseURLstr<-flags],listToMaybe[str|Flag_SourceModuleURLstr<-flags],listToMaybe[str|Flag_SourceEntityURLstr<-flags])wikiUrls::[Flag]->(MaybeString,MaybeString,MaybeString)wikiUrlsflags=(listToMaybe[str|Flag_WikiBaseURLstr<-flags],listToMaybe[str|Flag_WikiModuleURLstr<-flags],listToMaybe[str|Flag_WikiEntityURLstr<-flags])optDumpInterfaceFile::[Flag]->MaybeFilePathoptDumpInterfaceFileflags=optLast[str|Flag_DumpInterfacestr<-flags]optLaTeXStyle::[Flag]->MaybeStringoptLaTeXStyleflags=optLast[str|Flag_LaTeXStylestr<-flags]qualification::[Flag]->EitherStringQualOptionqualificationflags=casemap(mapChar.toLower)[str|Flag_Qualificationstr<-flags]of[]->RightOptNoQual["none"]->RightOptNoQual["full"]->RightOptFullQual["local"]->RightOptLocalQual["relative"]->RightOptRelativeQual["aliased"]->RightOptAliasedQual[arg]->Left$"unknown qualification type "++showarg_:_->Left"qualification option given multiple times"verbosity::[Flag]->Verbosityverbosityflags=case[str|Flag_Verbositystr<-flags]of[]->normalx:_->caseparseVerbosityxofLefte->throwEeRightv->vghcFlags::[Flag]->[String]ghcFlagsflags=[option|Flag_OptGhcoption<-flags]readIfaceArgs::[Flag]->[(DocPaths,FilePath)]readIfaceArgsflags=[parseIfaceOptions|Flag_ReadInterfaces<-flags]whereparseIfaceOption::String->(DocPaths,FilePath)parseIfaceOptionstr=casebreak(==',')strof(fpath,',':rest)->casebreak(==',')restof(src,',':file)->((fpath,Justsrc),file)(file,_)->((fpath,Nothing),file)(file,_)->(("",Nothing),file)-- | Like 'listToMaybe' but returns the last element instead of the first.optLast::[a]->MaybeaoptLast[]=NothingoptLastxs=Just(lastxs)