aboutsummaryrefslogtreecommitdiff
path: root/Command/Copy.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-07-09 15:23:14 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-07-09 15:23:14 -0400
commit87896574f32be5aa1636facc494faeab34cd0845 (patch)
treee3fe7c3572007aaa29eddd1f6ea2aebc07e40c3c /Command/Copy.hs
parent80603339ea4e8b93ef456e706ca8c4efeef341f8 (diff)
converted copy and move
Got a little tricky..
Diffstat (limited to 'Command/Copy.hs')
-rw-r--r--Command/Copy.hs57
1 files changed, 33 insertions, 24 deletions
diff --git a/Command/Copy.hs b/Command/Copy.hs
index 26ff8e263..a4f157e2f 100644
--- a/Command/Copy.hs
+++ b/Command/Copy.hs
@@ -15,34 +15,43 @@ import Annex.Wanted
import Annex.NumCopies
cmd :: Command
-cmd = withOptions copyOptions $
- command "copy" SectionCommon
- "copy content of files to/from another repository"
- paramPaths (withParams seek)
-
-copyOptions :: [Option]
-copyOptions = Command.Move.moveOptions ++ [autoOption]
-
-seek :: CmdParams -> CommandSeek
-seek ps = do
- to <- getOptionField toOption Remote.byNameWithUUID
- from <- getOptionField fromOption Remote.byNameWithUUID
- auto <- getOptionFlag autoOption
- withKeyOptions auto
- (Command.Move.startKey to from False)
- (withFilesInGit $ whenAnnexed $ start auto to from)
- ps
+cmd = command "copy" SectionCommon
+ "copy content of files to/from another repository"
+ paramPaths ((seek <=< finishParse) <$$> optParser)
+
+data CopyOptions = CopyOptions
+ { moveOptions :: Command.Move.MoveOptions
+ , autoMode :: Bool
+ }
+
+optParser :: CmdParamsDesc -> Parser CopyOptions
+optParser desc = CopyOptions
+ <$> Command.Move.optParser desc
+ <*> parseAutoOption
+
+instance DeferredParseClass CopyOptions where
+ finishParse v = CopyOptions
+ <$> finishParse (moveOptions v)
+ <*> pure (autoMode v)
+
+seek :: CopyOptions -> CommandSeek
+seek o = withKeyOptions (Command.Move.keyOptions $ moveOptions o) (autoMode o)
+ (Command.Move.startKey (moveOptions o) False)
+ (withFilesInGit $ whenAnnexed $ start o)
+ (Command.Move.moveFiles $ moveOptions o)
{- A copy is just a move that does not delete the source file.
- However, auto mode avoids unnecessary copies, and avoids getting or
- sending non-preferred content. -}
-start :: Bool -> Maybe Remote -> Maybe Remote -> FilePath -> Key -> CommandStart
-start auto to from file key = stopUnless shouldCopy $
- Command.Move.start to from False file key
+start :: CopyOptions -> FilePath -> Key -> CommandStart
+start o file key = stopUnless shouldCopy $
+ Command.Move.start (moveOptions o) False file key
where
shouldCopy
- | auto = want <||> numCopiesCheck file key (<)
+ | autoMode o = want <||> numCopiesCheck file key (<)
| otherwise = return True
- want = case to of
- Nothing -> wantGet False (Just key) (Just file)
- Just r -> wantSend False (Just key) (Just file) (Remote.uuid r)
+ want = case Command.Move.fromToOptions (moveOptions o) of
+ ToRemote _ ->
+ wantGet False (Just key) (Just file)
+ FromRemote dest -> (Remote.uuid <$> getParsed dest) >>=
+ wantSend False (Just key) (Just file)