addurl: Added --batch option.
authorJoey Hess <joeyh@joeyh.name>
Mon, 21 Dec 2015 16:57:13 +0000 (12:57 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 21 Dec 2015 16:57:13 +0000 (12:57 -0400)
CmdLine/Batch.hs
Command/AddUrl.hs
debian/changelog
doc/git-annex-addurl.mdwn

index 57823b67b8f34823d7e023e2b27ee9d261ca5e20..ce9127975ee96678cc3c8cb6a2966e29f813b37a 100644 (file)
@@ -12,15 +12,13 @@ import Command
 
 data BatchMode = Batch | NoBatch
 
-batchOption :: Parser BatchMode
-batchOption = flag NoBatch Batch
+parseBatchOption :: Parser BatchMode
+parseBatchOption = flag NoBatch Batch
        ( long "batch"
        <> help "enable batch mode"
        )
 
-type Batchable t = BatchMode -> t -> CommandStart
-
--- A Batchable command can run in batch mode, or not.
+-- A batchable command can run in batch mode, or not.
 -- In batch mode, one line at a time is read, parsed, and a reply output to
 -- stdout. In non batch mode, the command's parameters are parsed and
 -- a reply output for each.
@@ -29,7 +27,7 @@ batchable handler parser paramdesc = batchseeker <$> batchparser
   where
        batchparser = (,,)
                <$> parser
-               <*> batchOption
+               <*> parseBatchOption
                <*> cmdParams paramdesc
        
        batchseeker (opts, NoBatch, params) = mapM_ (go NoBatch opts) params
@@ -52,3 +50,13 @@ batchable handler parser paramdesc = batchseeker <$> batchparser
 batchBadInput :: BatchMode -> Annex ()
 batchBadInput NoBatch = liftIO exitFailure
 batchBadInput Batch = liftIO $ putStrLn ""
+
+-- Reads lines of batch mode input and passes to the action to handle.
+batchSeek :: (String -> Annex ()) -> Annex ()
+batchSeek a = do
+       mp <- liftIO $ catchMaybeIO getLine
+       case mp of
+               Nothing -> return ()
+               Just p -> do
+                       a p
+                       batchSeek a
index af2e04a62590f02410a9a73e0a7cbce8aa194338..de83d8c9b47ead9c06ef7186c78f057d6be54a66 100644 (file)
@@ -32,6 +32,7 @@ import Annex.Content.Direct
 import Annex.FileMatcher
 import Logs.Location
 import Utility.Metered
+import CmdLine.Batch
 import qualified Annex.Transfer as Transfer
 #ifdef WITH_QUVI
 import Annex.Quvi
@@ -51,6 +52,7 @@ data AddUrlOptions = AddUrlOptions
        , suffixOption :: Maybe String
        , relaxedOption :: Bool
        , rawOption :: Bool
+       , batchOption :: BatchMode
        }
 
 optParser :: CmdParamsDesc -> Parser AddUrlOptions
@@ -74,6 +76,7 @@ optParser desc = AddUrlOptions
                ))
        <*> parseRelaxedOption
        <*> parseRawOption
+       <*> parseBatchOption
 
 parseRelaxedOption :: Parser Bool
 parseRelaxedOption = switch
@@ -88,8 +91,13 @@ parseRawOption = switch
        )
 
 seek :: AddUrlOptions -> CommandSeek
-seek o = allowConcurrentOutput $
-       forM_ (addUrls o) $ \u -> do
+seek o = allowConcurrentOutput $ do
+       forM_ (addUrls o) go
+       case batchOption o of
+               Batch -> batchSeek go
+               NoBatch -> noop
+  where
+       go u = do
                r <- Remote.claimingUrl u
                if Remote.uuid r == webUUID || rawOption o
                        then void $ commandAction $ startWeb o u
index 99837e8641773c5472eb8b5329d2326921be5ff3..34e106d39a3a6b1070434ec0d79635b708696d9d 100644 (file)
@@ -4,6 +4,7 @@ git-annex (5.20151219) UNRELEASED; urgency=medium
     that were present. Probably caused by a change to what git status
     displays in this situation. Fixed by treating files git thinks are
     modified the same as typechanged files.
+  * addurl: Added --batch option. 
 
  -- Joey Hess <id@joeyh.name>  Sat, 19 Dec 2015 13:31:17 -0400
 
index 0f5a763bc1f3ab4f39430749f0d27a9724a8872f..eecc2c2bd8d9e99e571ab63e04d12d0825383ea9 100644 (file)
@@ -70,6 +70,11 @@ be used to get better filenames.
   Enables parallel downloads when multiple urls are being added.
   For example: `-J4`  
 
+* `--batch`
+
+  Enables batch mode, in which lines containing urls to add are read from
+  stdin.
+
 # SEE ALSO
 
 [[git-annex]](1)