-- Copyright (C) 2002-2004 David Roundy---- This program is free software; you can redistribute it and/or modify-- it under the terms of the GNU General Public License as published by-- the Free Software Foundation; either version 2, or (at your option)-- any later version.---- This program is distributed in the hope that it will be useful,-- but WITHOUT ANY WARRANTY; without even the implied warranty of-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-- GNU General Public License for more details.---- You should have received a copy of the GNU General Public License-- along with this program; see the file COPYING. If not, write to-- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,-- Boston, MA 02110-1301, USA.moduleDarcs.Commands.Help(helpCmd,commandControlList,environmentHelp,-- these are for preproc.hsprintVersion,listAvailableCommands)whereimportDarcs.Arguments(DarcsFlag(..),environmentHelpEmail,environmentHelpSendmail)importDarcs.Commands(CommandArgs(..),CommandControl(..),DarcsCommand(..),disambiguateCommands,extractCommands,getCommandHelp,nodefaults,usage)importDarcs.External(viewDoc)importDarcs.Lock(environmentHelpTmpdir,environmentHelpKeepTmpdir)importDarcs.Patch.Match(helpOnMatchers)importDarcs.Repository.Prefs(boringFileHelp,binariesFileHelp,environmentHelpHome)importDarcs.Ssh(environmentHelpSsh,environmentHelpScp,environmentHelpSshPort)importDarcs.Utils(withCurrentDirectory,environmentHelpEditor,environmentHelpPager)importData.Char(isAlphaNum,toLower,toUpper)importData.List(groupBy,isPrefixOf,partition,intercalate,nub)importData.Maybe(isNothing,mapMaybe)importEnglish(andClauses)importPrinter(text,vcat,vsep,($$))importSystem.Exit(ExitCode(..),exitWith)importVersion(version)importURL(environmentHelpProxy,environmentHelpProxyPassword)importWorkaround(getCurrentDirectory)importqualifiedDarcs.TheCommandsasTheCommandshelpDescription::StringhelpDescription="Display help about darcs and darcs commands."helpHelp::StringhelpHelp="Without arguments, `darcs help' prints a categorized list of darcs\n"++"commands and a short description of each one. With an extra argument,\n"++"`darcs help foo' prints detailed help about the darcs command foo.\n"help::DarcsCommandhelp=DarcsCommand{commandProgramName="darcs",commandName="help",commandHelp=helpHelp,commandDescription=helpDescription,commandExtraArgs=-1,commandExtraArgHelp=["[<DARCS_COMMAND> [DARCS_SUBCOMMAND]] "],commandCommand=\xy->helpCmdxy>>exitWithExitSuccess,commandPrereq=\_->return$Right(),commandGetArgPossibilities=return[],commandArgdefaults=nodefaults,commandAdvancedOptions=[],commandBasicOptions=[]}helpCmd::[DarcsFlag]->[String]->IO()helpCmd_["manpage"]=putStr$unlinesmanpageLineshelpCmd_["patterns"]=viewDoc$text$helpOnMatchershelpCmd_("environment":vs_)=viewDoc.vsep$ifnullvsthenheader:maprenderenvironmentHelpelsemaprenderknown++[footer]whereheader=vcat[text"Environment Variables",text"====================="]footer=text("Unknown environment variables: "++intercalate", "unknown)render(ks,ds)=text(andClausesks++":")$$vcat[text(" "++d)|d<-ds]lookupEnvv=[e|e@(ks,_)<-environmentHelp,v`elem`ks]unknown=[v|v<-vs,null(lookupEnvv)]known=nub(concatMaplookupEnvvs)vs=map(maptoUpper)vs_helpCmd_[]=viewDoc$text$usagecommandControlListhelpCmd_(cmd:args)=letdisambiguated=disambiguateCommandscommandControlListcmdargsincasedisambiguatedofLefterr->failerrRight(cmds,_)->letmsg=casecmdsofCommandOnlyc->getCommandHelpNothingcSuperCommandOnlyc->getCommandHelpNothingcSuperCommandSubcs->getCommandHelp(Justc)sinviewDoc$textmsglistAvailableCommands::IO()listAvailableCommands=dohere<-getCurrentDirectoryis_valid<-mapM(\c->withCurrentDirectoryhere$(commandPrereqc)[])(extractCommandscommandControlList)putStr$unlines$map(commandName.fst)$filter(isRight.snd)$zip(extractCommandscommandControlList)is_validputStrLn"--help"putStrLn"--version"putStrLn"--exact-version"putStrLn"--overview"whereisRight(Right_)=TrueisRight_=FalseprintVersion::IO()printVersion=putStrLn$"darcs version "++version-- avoiding a module import cycle between Help and TheCommandscommandControlList::[CommandControl]commandControlList=CommandDatahelp:TheCommands.commandControlList-- FIXME: the "grouping" comments below should made subsections in the-- manpage, as we already do for DarcsCommand groups. --twb, 2009-- | Help on each environment variable in which Darcs is interested.environmentHelp::[([String],[String])]environmentHelp=[-- General-purposeenvironmentHelpHome,environmentHelpEditor,environmentHelpPager,environmentHelpTmpdir,environmentHelpKeepTmpdir,environmentHelpEmail,environmentHelpSendmail,-- Remote RepositoriesenvironmentHelpSsh,environmentHelpScp,environmentHelpSshPort,environmentHelpProxy,environmentHelpProxyPassword]-- | This module is responsible for emitting a darcs "man-page", a-- reference document used widely on Unix-like systems. Manpages are-- primarily used as a quick reference, or "memory jogger", so the-- output should be terser than the user manual.---- Before modifying the output, please be sure to read the man(7) and-- man-pages(7) manpages, as these respectively describe the relevant-- syntax and conventions.-- | The lines of the manpage to be printed.manpageLines::[String]manpageLines=[".TH DARCS 1 \""++version++"\"",".SH NAME","darcs \\- an advanced revision control system",".SH SYNOPSIS",".B darcs",".I command",".RI < arguments |[ options ]>...","","Where the",".I commands","and their respective",".I arguments","are","",unlinessynopsis,".SH DESCRIPTION",-- FIXME: this is copy-and-pasted from darcs.cabal, so-- it'll get out of date as people forget to maintain-- both in sync."Darcs is a free, open source revision control","system. It is:",".TP 3","\\(bu","Distributed: Every user has access to the full","command set, removing boundaries between server and","client or committer and non\\(hycommitters.",".TP","\\(bu","Interactive: Darcs is easy to learn and efficient to","use because it asks you questions in response to","simple commands, giving you choices in your work","flow. You can choose to record one change in a file,","while ignoring another. As you update from upstream,","you can review each patch name, even the full `diff'","for interesting patches.",".TP","\\(bu","Smart: Originally developed by physicist David","Roundy, darcs is based on a unique algebra of","patches.","This smartness lets you respond to changing demands","in ways that would otherwise not be possible. Learn","more about spontaneous branches with darcs.",".SH OPTIONS","Different options are accepted by different Darcs commands.","Each command's most important options are listed in the",".B COMMANDS","section. For a full list of all options accepted by","a particular command, run `darcs",".I command","\\-\\-help'.",".SS "++escapehelpOnMatchers,-- FIXME: this is a kludge.".SH COMMANDS",unlinescommands,unlinesenvironment,".SH FILES",".SS \"_darcs/prefs/binaries\"",escape$unlinesbinariesFileHelp,".SS \"_darcs/prefs/boring\"",escape$unlinesboringFileHelp,".SH BUGS","At http://bugs.darcs.net/ you can find a list of known","bugs in Darcs. Unknown bugs can be reported at that","site (after creating an account) or by emailing the","report to bugs@darcs.net.",-- ".SH EXAMPLE",-- FIXME:-- new project: init, rec -la;-- track upstream project: get, pull -a;-- contribute to project: add, rec, push/send.".SH SEE ALSO","A user manual is included with Darcs, in PDF and HTML","form. It can also be found at http://darcs.net/manual/.",".SH LICENSE","Darcs is free software; you can redistribute it and/or modify","it under the terms of the GNU General Public License as published by","the Free Software Foundation; either version 2, or (at your option)","any later version."]where-- | A synopsis line for each command. Uses 'foldl' because it is-- necessary to avoid blank lines from Hidden_commands, as groff-- translates them into annoying vertical padding (unlike TeX).synopsis::[String]synopsis=foldliter[]commandControlListwhereiter::[String]->CommandControl->[String]iteracc(GroupName_)=acciteracc(HiddenCommand_)=acciteracc(CommandDatac@SuperCommand{})=acc++concatMap(render(commandNamec++" "))(extractCommands(commandSubCommandsc))iteracc(CommandDatac)=acc++render""crender::String->DarcsCommand->[String]renderprefixc=[".B darcs "++prefix++commandNamec]++(mapmangle_args$commandExtraArgHelpc)++-- In the output, we want each command to be on its own-- line, but we don't want blank lines between them.-- AFAICT this can only be achieved with the .br-- directive, which is probably a GNUism.[".br"]-- | As 'synopsis', but make each group a subsection (.SS), and-- include the help text for each command.commands::[String]commands=foldliter[]commandControlListwhereiter::[String]->CommandControl->[String]iteracc(GroupNamex)=acc++[".SS \""++x++"\""]iteracc(HiddenCommand_)=acciteracc(CommandDatac@SuperCommand{})=acc++concatMap(render(commandNamec++" "))(extractCommands(commandSubCommandsc))iteracc(CommandDatac)=acc++render""crender::String->DarcsCommand->[String]renderprefixc=[".B darcs "++prefix++commandNamec]++(mapmangle_args$commandExtraArgHelpc)++[".RS 4",escape$commandHelpc,".RE"]-- | Now I'm showing off: mangle the extra arguments of Darcs commands-- so as to use the ideal format for manpages, italic words and roman-- punctuation.mangle_args::String->Stringmangle_argss=".RI "++(unwords$mapshow(groupBycmp$maptoLower$ganks))wherecmpxy=not$xor(isAlphaNumx)(isAlphaNumy)xorxy=(x&&noty)||(y&&notx)gank(' ':'o':'r':' ':xs)='|':gankxsgank(x:xs)=x:gankxsgank[]=[]environment::[String]environment=".SH ENVIRONMENT":concat[(".SS \""++andClausesks++"\""):mapescapeds|(ks,ds)<-environmentHelp]-- | Copied from Preproc.escape_latex_specials.escape::String->Stringescape=minus.bs-- Order is importantwhereminus=replace"-""\\-"bs=replace"\\""\\\\"replace::Eqa=>[a]->[a]->[a]->[a]replace__[]=[]replacefindrepls=iffind`isPrefixOf`sthenrepl++(replacefindrepl(drop(lengthfind)s))else[heads]++replacefindrepl(tails)