fix --json-progress --json to be same as --json --json-progress

Fix behavior of --json-progress followed by --json, in which
the latter option disabled the former.

This commit was supported by the NSF-funded DataLad project.
This commit is contained in:
Joey Hess 2018-02-19 14:03:23 -04:00
parent 8ccfbd14d0
commit fa65f1d240
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 35 additions and 12 deletions

View file

@ -275,7 +275,8 @@ addCleanup k a = changeState $ \s ->
{- Sets the type of output to emit. -} {- Sets the type of output to emit. -}
setOutput :: OutputType -> Annex () setOutput :: OutputType -> Annex ()
setOutput o = changeState $ \s -> setOutput o = changeState $ \s ->
s { output = (output s) { outputType = o } } let m = output s
in s { output = m { outputType = adjustOutputType (outputType m) o } }
{- Checks if a flag was set. -} {- Checks if a flag was set. -}
getFlag :: String -> Annex Bool getFlag :: String -> Annex Bool

View file

@ -17,6 +17,8 @@ git-annex (6.20180113) UNRELEASED; urgency=medium
hopefully hackage finally recognises that OS. hopefully hackage finally recognises that OS.
* Split Test.hs and avoid optimising it much, to need less memory to * Split Test.hs and avoid optimising it much, to need less memory to
compile. compile.
* Fix behavior of --json-progress followed by --json, in which
the latter option disabled the former.
-- Joey Hess <id@joeyh.name> Wed, 24 Jan 2018 20:42:55 -0400 -- Joey Hess <id@joeyh.name> Wed, 24 Jan 2018 20:42:55 -0400

View file

@ -295,18 +295,26 @@ combiningOptions =
shortopt o h = globalFlag (Limit.addToken [o]) ( short o <> help h <> hidden ) shortopt o h = globalFlag (Limit.addToken [o]) ( short o <> help h <> hidden )
jsonOption :: GlobalOption jsonOption :: GlobalOption
jsonOption = globalFlag (Annex.setOutput (JSONOutput False)) jsonOption = globalFlag (Annex.setOutput (JSONOutput jsonoptions))
( long "json" <> short 'j' ( long "json" <> short 'j'
<> help "enable JSON output" <> help "enable JSON output"
<> hidden <> hidden
) )
where
jsonoptions = JSONOptions
{ jsonProgress = False
}
jsonProgressOption :: GlobalOption jsonProgressOption :: GlobalOption
jsonProgressOption = globalFlag (Annex.setOutput (JSONOutput True)) jsonProgressOption = globalFlag (Annex.setOutput (JSONOutput jsonoptions))
( long "json-progress" ( long "json-progress"
<> help "include progress in JSON output" <> help "include progress in JSON output"
<> hidden <> hidden
) )
where
jsonoptions = JSONOptions
{ jsonProgress = True
}
-- Note that a command that adds this option should wrap its seek -- Note that a command that adds this option should wrap its seek
-- action in `allowConcurrentOutput`. -- action in `allowConcurrentOutput`.

View file

@ -55,12 +55,13 @@ metered othermeter key getsrcfile a = withMessageState $ \st ->
#else #else
nometer nometer
#endif #endif
go _ (MessageState { outputType = JSONOutput False }) = nometer go msize (MessageState { outputType = JSONOutput jsonoptions })
go msize (MessageState { outputType = JSONOutput True }) = do | jsonProgress jsonoptions = do
buf <- withMessageState $ return . jsonBuffer buf <- withMessageState $ return . jsonBuffer
m <- liftIO $ rateLimitMeterUpdate 0.1 msize $ m <- liftIO $ rateLimitMeterUpdate 0.1 msize $
JSON.progress buf msize JSON.progress buf msize
a (combinemeter m) a (combinemeter m)
| otherwise = nometer
nometer = a $ combinemeter (const noop) nometer = a $ combinemeter (const noop)
@ -96,7 +97,7 @@ meteredFile file combinemeterupdate key a =
needOutputMeter :: MessageState -> Bool needOutputMeter :: MessageState -> Bool
needOutputMeter s = case outputType s of needOutputMeter s = case outputType s of
JSONOutput True -> True JSONOutput jsonoptions -> jsonProgress jsonoptions
NormalOutput | concurrentOutputEnabled s -> True NormalOutput | concurrentOutputEnabled s -> True
_ -> False _ -> False

View file

@ -1,6 +1,6 @@
{- git-annex Messages data types {- git-annex Messages data types
- -
- Copyright 2012-2017 Joey Hess <id@joeyh.name> - Copyright 2012-2018 Joey Hess <id@joeyh.name>
- -
- Licensed under the GNU GPL version 3 or higher. - Licensed under the GNU GPL version 3 or higher.
-} -}
@ -16,9 +16,20 @@ import Control.Concurrent
import System.Console.Regions (ConsoleRegion) import System.Console.Regions (ConsoleRegion)
#endif #endif
data OutputType = NormalOutput | QuietOutput | JSONOutput Bool data OutputType = NormalOutput | QuietOutput | JSONOutput JSONOptions
deriving (Show) deriving (Show)
data JSONOptions = JSONOptions
{ jsonProgress :: Bool
}
deriving (Show)
adjustOutputType :: OutputType -> OutputType -> OutputType
adjustOutputType (JSONOutput old) (JSONOutput new) = JSONOutput $ JSONOptions
{ jsonProgress = jsonProgress old || jsonProgress new
}
adjustOutputType _old new = new
data SideActionBlock = NoBlock | StartBlock | InBlock data SideActionBlock = NoBlock | StartBlock | InBlock
deriving (Eq) deriving (Eq)