diff options
author | 2016-12-07 14:32:25 -0400 | |
---|---|---|
committer | 2016-12-07 14:32:25 -0400 | |
commit | 9350f8871f5498a34c99bed209799b9fbb6391d3 (patch) | |
tree | 369db25e472126dbea8feeb7ec70dbca404da66c /Command/RmUrl.hs | |
parent | 51b648ac6e11d0d5a9e617e45d236bd850894285 (diff) | |
parent | 3500fa70e016459fcd02cba4d4c3059e7f4555ef (diff) |
Merge branch 'master' into tor
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 |