summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-04-03 20:38:56 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-04-03 20:38:56 -0400
commitb3b8a1cdfdc583159c117ebe76e3c6a4eb57114b (patch)
tree59fea875dd28b37bfe78f157108523b4c8e01305
parentf1cb897e78ca0f972a909ebd0258e1f25e13fb66 (diff)
avoid progress bar for url download with --quiet
-rw-r--r--Annex/Content.hs16
-rw-r--r--Messages/Progress.hs24
2 files changed, 30 insertions, 10 deletions
diff --git a/Annex/Content.hs b/Annex/Content.hs
index f91c1e72a..977e92d51 100644
--- a/Annex/Content.hs
+++ b/Annex/Content.hs
@@ -57,6 +57,7 @@ import Annex.Link
import Annex.Content.Direct
import Annex.ReplaceFile
import Utility.LockFile
+import Messages.Progress
{- Checks if a given key's content is currently present. -}
inAnnex :: Key -> Annex Bool
@@ -555,12 +556,17 @@ saveState nocommit = doSideAction $ do
downloadUrl :: [Url.URLString] -> FilePath -> Annex Bool
downloadUrl urls file = go =<< annexWebDownloadCommand <$> Annex.getGitConfig
where
- go Nothing = Url.withUrlOptions $ \uo ->
- anyM (\u -> Url.download u file uo) urls
- go (Just basecmd) = liftIO $ anyM (downloadcmd basecmd) urls
+ go Nothing = do
+ a <- ifM commandProgressDisabled
+ ( return Url.downloadQuiet
+ , return Url.download
+ )
+ Url.withUrlOptions $ \uo ->
+ anyM (\u -> a u file uo) urls
+ go (Just basecmd) = anyM (downloadcmd basecmd) urls
downloadcmd basecmd url =
- boolSystem "sh" [Param "-c", Param $ gencmd url basecmd]
- <&&> doesFileExist file
+ progressCommand stderr "sh" [Param "-c", Param $ gencmd url basecmd]
+ <&&> liftIO (doesFileExist file)
gencmd url = massReplace
[ ("%file", shellEscape file)
, ("%url", shellEscape url)
diff --git a/Messages/Progress.hs b/Messages/Progress.hs
index acc237017..cb55a8c28 100644
--- a/Messages/Progress.hs
+++ b/Messages/Progress.hs
@@ -49,20 +49,34 @@ showProgressDots :: Annex ()
showProgressDots = handleMessage q $
flushed $ putStr "."
+{- Runs a command, that normally outputs progress to the specified handle.
+ -
+ - In quiet mode, normal output is suppressed. stderr is fed through the
+ - mkStderrEmitter. If the progress is output to stderr, then stderr is
+ - dropped, unless the command fails in which case the last line of output
+ - to stderr will be shown.
+ -}
+progressCommand :: Handle -> FilePath -> [CommandParam] -> Annex Bool
+progressCommand progresshandle cmd params = undefined
+
mkProgressHandler :: MeterUpdate -> Annex ProgressHandler
mkProgressHandler meter = ProgressHandler
- <$> quietmode
+ <$> commandProgressDisabled
<*> (stderrhandler <$> mkStderrEmitter)
<*> pure meter
where
- quietmode = withOutputType $ \t -> return $ case t of
- QuietOutput -> True
- ProgressOutput -> True
- _ -> False
stderrhandler emitter h = unlessM (hIsEOF h) $ do
void $ emitter =<< hGetLine h
stderrhandler emitter h
+{- Should commands that normally output progress messages have that
+ - output disabled? -}
+commandProgressDisabled :: Annex Bool
+commandProgressDisabled = withOutputType $ \t -> return $ case t of
+ QuietOutput -> True
+ ProgressOutput -> True
+ _ -> False
+
{- Generates an IO action that can be used to emit stderr.
-
- When a progress meter is displayed, this takes care to avoid