diff options
Diffstat (limited to 'Command/RmUrl.hs')
-rw-r--r-- | Command/RmUrl.hs | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/Command/RmUrl.hs b/Command/RmUrl.hs index eb78f7ba7..1a547a71e 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. -} @@ -15,13 +15,33 @@ 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 |