summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Command/Copy.hs2
-rw-r--r--Command/Drop.hs2
-rw-r--r--Command/Find.hs4
-rw-r--r--Command/Get.hs2
-rw-r--r--Command/Move.hs2
-rw-r--r--Seek.hs11
6 files changed, 13 insertions, 10 deletions
diff --git a/Command/Copy.hs b/Command/Copy.hs
index a9491f56f..d789d41f6 100644
--- a/Command/Copy.hs
+++ b/Command/Copy.hs
@@ -16,7 +16,7 @@ def = [withOptions Command.Move.options $ command "copy" paramPaths seek
"copy content of files to/from another repository"]
seek :: [CommandSeek]
-seek = [withField "to" $ \to -> withField "from" $ \from ->
+seek = [withField "to" id $ \to -> withField "from" id $ \from ->
withNumCopies $ \n -> whenAnnexed $ start to from n]
-- A copy is just a move that does not delete the source file.
diff --git a/Command/Drop.hs b/Command/Drop.hs
index 3ad407703..f76951f08 100644
--- a/Command/Drop.hs
+++ b/Command/Drop.hs
@@ -25,7 +25,7 @@ fromOption :: Option
fromOption = fieldOption ['f'] "from" paramRemote "drop content from a remote"
seek :: [CommandSeek]
-seek = [withField "from" $ \from -> withNumCopies $ \n ->
+seek = [withField "from" id $ \from -> withNumCopies $ \n ->
whenAnnexed $ start from n]
start :: Maybe String -> Maybe Int -> FilePath -> (Key, Backend) -> CommandStart
diff --git a/Command/Find.hs b/Command/Find.hs
index bc7f200c2..eb0267c14 100644
--- a/Command/Find.hs
+++ b/Command/Find.hs
@@ -30,8 +30,8 @@ formatOption :: Option
formatOption = fieldOption [] "format" paramFormat "control format of output"
seek :: [CommandSeek]
-seek = [withField "format" $ \f ->
- withFilesInGit $ whenAnnexed $ start $ formatconverter f]
+seek = [withField "format" formatconverter $ \f ->
+ withFilesInGit $ whenAnnexed $ start f]
where
formatconverter = maybe Nothing (Just . Utility.Format.gen)
diff --git a/Command/Get.hs b/Command/Get.hs
index c3a6630ce..4a50fe3fe 100644
--- a/Command/Get.hs
+++ b/Command/Get.hs
@@ -18,7 +18,7 @@ def = [withOptions [Command.Move.fromOption] $ command "get" paramPaths seek
"make content of annexed files available"]
seek :: [CommandSeek]
-seek = [withField "from" $ \from -> withNumCopies $ \n ->
+seek = [withField "from" id $ \from -> withNumCopies $ \n ->
whenAnnexed $ start from n]
start :: Maybe String -> Maybe Int -> FilePath -> (Key, Backend) -> CommandStart
diff --git a/Command/Move.hs b/Command/Move.hs
index b6a72bf6b..66a0c1660 100644
--- a/Command/Move.hs
+++ b/Command/Move.hs
@@ -29,7 +29,7 @@ options :: [Option]
options = [fromOption, toOption]
seek :: [CommandSeek]
-seek = [withField "to" $ \to -> withField "from" $ \from ->
+seek = [withField "to" id $ \to -> withField "from" id $ \from ->
withFilesInGit $ whenAnnexed $ start to from True]
start :: Maybe String -> Maybe String -> Bool -> FilePath -> (Key, Backend) -> CommandStart
diff --git a/Seek.hs b/Seek.hs
index 2c121bd96..af074c7c5 100644
--- a/Seek.hs
+++ b/Seek.hs
@@ -87,10 +87,13 @@ withKeys a params = return $ map (a . parse) params
where
parse p = fromMaybe (error "bad key") $ readKey p
-{- Feeds the value of a field to a seek action. -}
-withField :: String -> (Maybe String -> CommandSeek) -> CommandSeek
-withField field a ps = do
- f <- Annex.getField field
+{- Modifies a seek action using the value of a field, which is fed into
+ - a conversion function, and then is passed into the seek action.
+ - This ensures that the conversion function only runs once.
+ -}
+withField :: String -> (Maybe String -> a) -> (a -> CommandSeek) -> CommandSeek
+withField field converter a ps = do
+ f <- converter <$> Annex.getField field
a f ps
withNothing :: CommandStart -> CommandSeek