1 -- Copyright (C) 2002-2004 David Roundy 2 -- 3 -- This program is free software; you can redistribute it and/or modify 4 -- it under the terms of the GNU General Public License as published by 5 -- the Free Software Foundation; either version 2, or (at your option) 6 -- any later version. 7 -- 8 -- This program is distributed in the hope that it will be useful, 9 -- but WITHOUT ANY WARRANTY; without even the implied warranty of 10 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 -- GNU General Public License for more details. 12 -- 13 -- You should have received a copy of the GNU General Public License 14 -- along with this program; see the file COPYING. If not, write to 15 -- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 -- Boston, MA 02110-1301, USA. 17 18 module Darcs.Flags ( DarcsFlag( .. ), Compression( .. ), compression, want_external_merge, isInteractive, 19 maxCount, 20 ) where 21 import Darcs.Patch.MatchData ( PatchMatch ) 22 import Darcs.RepoPath ( AbsolutePath, AbsolutePathOrStd ) 23 24 -- | The 'DarcsFlag' type is a list of all flags that can ever be 25 -- passed to darcs, or to one of its commands. 26 data DarcsFlag = Help | ListOptions | NoTest | Test 27 | OnlyChangesToFiles 28 | LeaveTestDir | NoLeaveTestDir 29 | Timings | Debug | DebugVerbose | DebugHTTP 30 | Verbose | NormalVerbosity | Quiet 31 | Target String | Cc String 32 | Output AbsolutePathOrStd | OutputAutoName AbsolutePath 33 | Subject String | InReplyTo String 34 | SendmailCmd String | Author String | PatchName String 35 | OnePatch String | SeveralPatch String 36 | AfterPatch String | UpToPatch String 37 | TagName String | LastN Int | MaxCount Int | PatchIndexRange Int Int 38 | NumberPatches 39 | OneTag String | AfterTag String | UpToTag String 40 | Context AbsolutePath | Count 41 | LogFile AbsolutePath | RmLogFile 42 | DistName String | All 43 | Recursive | NoRecursive | Reorder 44 | RestrictPaths | DontRestrictPaths 45 | AskDeps | NoAskDeps | IgnoreTimes | LookForAdds | NoLookForAdds 46 | AnyOrder | CreatorHash String 47 | Intersection | Union | Complement 48 | Sign | SignAs String | NoSign | SignSSL String 49 | HappyForwarding 50 | Verify AbsolutePath | VerifySSL AbsolutePath 51 | SSHControlMaster | NoSSHControlMaster 52 | EditDescription | NoEditDescription 53 | Toks String 54 | EditLongComment | NoEditLongComment | PromptLongComment 55 | AllowConflicts | MarkConflicts | NoAllowConflicts 56 | Boring | AllowCaseOnly | AllowWindowsReserved 57 | DontGrabDeps | DontPromptForDependencies | PromptForDependencies 58 | Compress | NoCompress | UnCompress 59 | WorkRepoDir String | WorkRepoUrl String | RemoteRepo String 60 | NewRepo String 61 | Reply String | ApplyAs String 62 | MachineReadable | HumanReadable 63 | Pipe | Interactive 64 | DiffCmd String 65 | ExternalMerge String | Summary | NoSummary 66 | Unified | Reverse 67 | Partial | Complete | Lazy | Ephemeral 68 | FixFilePath AbsolutePath AbsolutePath | DiffFlags String 69 | XMLOutput 70 | ForceReplace 71 | OnePattern PatchMatch | SeveralPattern PatchMatch 72 | AfterPattern PatchMatch | UpToPattern PatchMatch 73 | NonApply | NonVerify | NonForce 74 | DryRun | SetDefault | NoSetDefault 75 | FancyMoveAdd | NoFancyMoveAdd 76 | Disable | SetScriptsExecutable | DontSetScriptsExecutable 77 | UseHashedInventory | UseOldFashionedInventory 78 | UseFormat2 79 | PristinePlain | PristineNone | NoUpdateWorking 80 | Sibling AbsolutePath | Relink | RelinkPristine | NoLinks 81 | Files | NoFiles | Directories | NoDirectories 82 | Pending | NoPending 83 | PosthookCmd String | NoPosthook | AskPosthook | RunPosthook 84 | PrehookCmd String | NoPrehook | AskPrehook | RunPrehook 85 | UMask String 86 | StoreInMemory 87 | HTTPPipelining | NoHTTPPipelining 88 | NoCache 89 | AllowUnrelatedRepos 90 | Check | Repair | JustThisRepo 91 | NullFlag 92 deriving ( Eq, Show ) 93 94 data Compression = NoCompression | GzipCompression 95 compression :: [DarcsFlag] -> Compression 96 compression f | NoCompress `elem` f = NoCompression 97 | otherwise = GzipCompression 98 99 want_external_merge :: [DarcsFlag] -> Maybe String 100 want_external_merge [] = Nothing 101 want_external_merge (ExternalMerge c:_) = Just c 102 want_external_merge (_:fs) = want_external_merge fs 103 104 isInteractive :: [DarcsFlag] -> Bool 105 isInteractive = isInteractive_ True 106 where 107 isInteractive_ def [] = def 108 isInteractive_ _ (Interactive:_) = True 109 isInteractive_ _ (All:_) = False 110 isInteractive_ _ (DryRun:fs) = isInteractive_ False fs 111 isInteractive_ def (_:fs) = isInteractive_ def fs 112 113 maxCount :: [DarcsFlag] -> Maybe Int 114 maxCount (MaxCount n : _) = Just n 115 maxCount (_:xs) = maxCount xs 116 maxCount [] = Nothing