From 93852dd7e8403e69c1d7b1334609c016202b0f46 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 5 Dec 2016 12:10:07 -0400 Subject: [PATCH] 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. --- CHANGELOG | 3 +++ Command/RmUrl.hs | 33 +++++++++++++++++++++++++++------ doc/git-annex-rmurl.mdwn | 14 +++++++++++++- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 76da79eaaf..384dc3c3bc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,9 @@ git-annex (6.20161119) UNRELEASED; urgency=medium does not support graphical display, while xdot does. * Debian: xdot is a better interactive viewer than dot, so Suggest xdot, rather than graphviz. + * rmurl: Multiple pairs of files and urls can be provided on the + command line. + * rmurl: Added --batch mode. -- Joey Hess Mon, 21 Nov 2016 11:27:50 -0400 diff --git a/Command/RmUrl.hs b/Command/RmUrl.hs index eb78f7ba7e..0f33d66b2d 100644 --- a/Command/RmUrl.hs +++ b/Command/RmUrl.hs @@ -1,6 +1,6 @@ {- git-annex command - - - Copyright 2013 Joey Hess + - Copyright 2013-2016 Joey Hess - - 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 diff --git a/doc/git-annex-rmurl.mdwn b/doc/git-annex-rmurl.mdwn index 5faf9ea39e..e971e622e6 100644 --- a/doc/git-annex-rmurl.mdwn +++ b/doc/git-annex-rmurl.mdwn @@ -4,12 +4,24 @@ git-annex rmurl - record file is not available at url # SYNOPSIS -git annex rmurl `file url` +git annex rmurl `[file url ..]` # DESCRIPTION Record that the file is no longer available at the url. +If nothing is specified on the command line, they are instead read +from stdin. Any number of lines can be provided in this mode, +each containing a file and and url, separated by a single space. + +# OPTIONS + +* `--batch` + + Enables batch mode, in which lines are read from stdin. + Each line should contain the file, and the url to remove from that file, + separated by a single space. + # SEE ALSO [[git-annex]](1)