aboutsummaryrefslogtreecommitdiff
path: root/Command
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
parent80603339ea4e8b93ef456e706ca8c4efeef341f8 (diff)
converted copy and move
Got a little tricky..
Diffstat (limited to 'Command')
-rw-r--r--Command/Copy.hs57
-rw-r--r--Command/Drop.hs16
-rw-r--r--Command/Fsck.hs1
-rw-r--r--Command/Move.hs79
-rw-r--r--Command/TransferInfo.hs4
5 files changed, 87 insertions, 70 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)
diff --git a/Command/Drop.hs b/Command/Drop.hs
index 3f4ea1a9d..1c595b6c2 100644
--- a/Command/Drop.hs
+++ b/Command/Drop.hs
@@ -19,10 +19,8 @@ import Annex.NumCopies
import Annex.Content
import Annex.Wanted
import Annex.Notification
-import Git.Types (RemoteName)
import qualified Data.Set as S
-import Options.Applicative hiding (command)
cmd :: Command
cmd = command "drop" SectionCommon
@@ -31,9 +29,9 @@ cmd = command "drop" SectionCommon
data DropOptions = DropOptions
{ dropFiles :: CmdParams
- , dropFrom :: Maybe RemoteName
+ , dropFrom :: Maybe (DeferredParse Remote)
, autoMode :: Bool
- , keyOptions :: KeyOptions
+ , keyOptions :: Maybe KeyOptions
}
-- TODO: annexedMatchingOptions
@@ -41,12 +39,12 @@ data DropOptions = DropOptions
optParser :: CmdParamsDesc -> Parser DropOptions
optParser desc = DropOptions
<$> cmdParams desc
- <*> parseDropFromOption
+ <*> optional parseDropFromOption
<*> parseAutoOption
- <*> parseKeyOptions False
+ <*> optional (parseKeyOptions False)
-parseDropFromOption :: Parser (Maybe RemoteName)
-parseDropFromOption = optional $ strOption
+parseDropFromOption :: Parser (DeferredParse Remote)
+parseDropFromOption = parseRemoteOption $ strOption
( long "from" <> short 'f' <> metavar paramRemote
<> help "drop content from a remote"
)
@@ -62,7 +60,7 @@ start o file key = start' o key (Just file)
start' :: DropOptions -> Key -> AssociatedFile -> CommandStart
start' o key afile = do
- from <- Remote.byNameWithUUID (dropFrom o)
+ from <- maybe (pure Nothing) (Just <$$> getParsed) (dropFrom o)
checkDropAuto (autoMode o) from afile key $ \numcopies ->
stopUnless (want from) $
case from of
diff --git a/Command/Fsck.hs b/Command/Fsck.hs
index 09a3a82c9..dbeeefbcd 100644
--- a/Command/Fsck.hs
+++ b/Command/Fsck.hs
@@ -40,7 +40,6 @@ import qualified Database.Fsck as FsckDb
import Data.Time.Clock.POSIX
import System.Posix.Types (EpochTime)
-import Options.Applicative hiding (command)
cmd :: Command
cmd = command "fsck" SectionMaintenance
diff --git a/Command/Move.hs b/Command/Move.hs
index fc13ca254..153114f8b 100644
--- a/Command/Move.hs
+++ b/Command/Move.hs
@@ -18,36 +18,47 @@ import Annex.Transfer
import Logs.Presence
cmd :: Command
-cmd = withOptions moveOptions $
- command "move" SectionCommon
- "move content of files to/from another repository"
- paramPaths (withParams seek)
-
-moveOptions :: [Option]
-moveOptions = fromToOptions ++ [jobsOption] ++ keyOptions ++ annexedMatchingOptions
-
-seek :: CmdParams -> CommandSeek
-seek ps = do
- to <- getOptionField toOption Remote.byNameWithUUID
- from <- getOptionField fromOption Remote.byNameWithUUID
- withKeyOptions False
- (startKey to from True)
- (withFilesInGit $ whenAnnexed $ start to from True)
- ps
-
-start :: Maybe Remote -> Maybe Remote -> Bool -> FilePath -> Key -> CommandStart
-start to from move = start' to from move . Just
-
-startKey :: Maybe Remote -> Maybe Remote -> Bool -> Key -> CommandStart
-startKey to from move = start' to from move Nothing
-
-start' :: Maybe Remote -> Maybe Remote -> Bool -> AssociatedFile -> Key -> CommandStart
-start' to from move afile key = do
- case (from, to) of
- (Nothing, Nothing) -> error "specify either --from or --to"
- (Nothing, Just dest) -> toStart dest move afile key
- (Just src, Nothing) -> fromStart src move afile key
- _ -> error "only one of --from or --to can be specified"
+cmd = command "move" SectionCommon
+ "move content of files to/from another repository"
+ paramPaths ((seek <=< finishParse) <$$> optParser)
+
+data MoveOptions = MoveOptions
+ { moveFiles :: CmdParams
+ , fromToOptions :: FromToOptions
+ , keyOptions :: Maybe KeyOptions
+ }
+
+-- TODO: jobsOption, annexedMatchingOptions
+
+optParser :: CmdParamsDesc -> Parser MoveOptions
+optParser desc = MoveOptions
+ <$> cmdParams desc
+ <*> parseFromToOptions
+ <*> optional (parseKeyOptions False)
+
+instance DeferredParseClass MoveOptions where
+ finishParse v = MoveOptions
+ <$> pure (moveFiles v)
+ <*> finishParse (fromToOptions v)
+ <*> pure (keyOptions v)
+
+seek :: MoveOptions -> CommandSeek
+seek o = withKeyOptions (keyOptions o) False
+ (startKey o True)
+ (withFilesInGit $ whenAnnexed $ start o True)
+ (moveFiles o)
+
+start :: MoveOptions -> Bool -> FilePath -> Key -> CommandStart
+start o move = start' o move . Just
+
+startKey :: MoveOptions -> Bool -> Key -> CommandStart
+startKey o move = start' o move Nothing
+
+start' :: MoveOptions -> Bool -> AssociatedFile -> Key -> CommandStart
+start' o move afile key =
+ case fromToOptions o of
+ FromRemote src -> fromStart move afile key =<< getParsed src
+ ToRemote dest -> toStart move afile key =<< getParsed dest
showMoveAction :: Bool -> Key -> AssociatedFile -> Annex ()
showMoveAction move = showStart' (if move then "move" else "copy")
@@ -61,8 +72,8 @@ showMoveAction move = showStart' (if move then "move" else "copy")
- A file's content can be moved even if there are insufficient copies to
- allow it to be dropped.
-}
-toStart :: Remote -> Bool -> AssociatedFile -> Key -> CommandStart
-toStart dest move afile key = do
+toStart :: Bool -> AssociatedFile -> Key -> Remote -> CommandStart
+toStart move afile key dest = do
u <- getUUID
ishere <- inAnnex key
if not ishere || u == Remote.uuid dest
@@ -124,8 +135,8 @@ toPerform dest move key afile fastcheck isthere =
- If the current repository already has the content, it is still removed
- from the remote.
-}
-fromStart :: Remote -> Bool -> AssociatedFile -> Key -> CommandStart
-fromStart src move afile key
+fromStart :: Bool -> AssociatedFile -> Key -> Remote -> CommandStart
+fromStart move afile key src
| move = go
| otherwise = stopUnless (not <$> inAnnex key) go
where
diff --git a/Command/TransferInfo.hs b/Command/TransferInfo.hs
index d102be55e..2b5713d77 100644
--- a/Command/TransferInfo.hs
+++ b/Command/TransferInfo.hs
@@ -49,8 +49,8 @@ start (k:[]) = do
, transferUUID = u
, transferKey = key
}
- info <- liftIO $ startTransferInfo file
- (update, tfile, _) <- mkProgressUpdater t info
+ tinfo <- liftIO $ startTransferInfo file
+ (update, tfile, _) <- mkProgressUpdater t tinfo
liftIO $ mapM_ void
[ tryIO $ forever $ do
bytes <- readUpdate