aboutsummaryrefslogtreecommitdiff
path: root/Command/RmUrl.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-12-05 12:10:07 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-12-05 12:10:07 -0400
commit10d60a652cd7d374a6e54ef0255bb54f17fafb31 (patch)
tree20916de7c7e4fb9ec0265876747714606f8d8554 /Command/RmUrl.hs
parentc6970ef134cdc376fad48fbd8eb79c562d434e7c (diff)
rmurl: --batch
* rmurl: Multiple pairs of files and urls can be provided on the command line. * rmurl: Added --batch mode. This commit was sponsored by Trenton Cronholm on Patreon.
Diffstat (limited to 'Command/RmUrl.hs')
-rw-r--r--Command/RmUrl.hs33
1 files changed, 27 insertions, 6 deletions
diff --git a/Command/RmUrl.hs b/Command/RmUrl.hs
index eb78f7ba7..0f33d66b2 100644
--- a/Command/RmUrl.hs
+++ b/Command/RmUrl.hs
@@ -1,6 +1,6 @@
{- git-annex command
-
- - Copyright 2013 Joey Hess <id@joeyh.name>
+ - Copyright 2013-2016 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -10,18 +10,39 @@ module Command.RmUrl where
import Command
import Logs.Web
import qualified Remote
+import CmdLine.Batch
cmd :: Command
cmd = notBareRepo $
command "rmurl" SectionCommon
"record file is not available at url"
- (paramPair paramFile paramUrl)
- (withParams seek)
+ (paramRepeating (paramPair paramFile paramUrl))
+ (seek <$$> optParser)
-seek :: CmdParams -> CommandSeek
-seek = withPairs start
+data RmUrlOptions = RmUrlOptions
+ { rmThese :: CmdParams
+ , batchOption :: BatchMode
+ }
-start :: (FilePath, String) -> CommandStart
+optParser :: CmdParamsDesc -> Parser RmUrlOptions
+optParser desc = RmUrlOptions
+ <$> cmdParams desc
+ <*> parseBatchOption
+
+seek :: RmUrlOptions -> CommandSeek
+seek o = case batchOption o of
+ Batch -> batchInput batchParser (batchCommandAction . start)
+ NoBatch -> withPairs start (rmThese o)
+
+-- Split on the last space, since a FilePath can contain whitespace,
+-- but a url should not.
+batchParser :: String -> Either String (FilePath, URLString)
+batchParser s = case separate (== ' ') (reverse s) of
+ (ru, rf)
+ | null ru || null rf -> Left "Expected: \"file url\""
+ | otherwise -> Right (reverse rf, reverse ru)
+
+start :: (FilePath, URLString) -> CommandStart
start (file, url) = flip whenAnnexed file $ \_ key -> do
showStart "rmurl" file
next $ next $ cleanup url key