make noMessages disable closing of json object in --json mode
This allows things like Command.Find to use noMessages and generate their own complete json objects. Previouly, Command.Find managed that only via a hack, which wasn't compatable with batch mode. Only Command.Find, Command.Smudge, and Commange.Status use noMessages currently, and none except for Command.Find are impacted by this change. Fixes find --json --batch output
This commit is contained in:
parent
7aac76d40e
commit
70b8cad9c8
7 changed files with 26 additions and 11 deletions
|
@ -39,8 +39,10 @@ dispatch fuzzyok allargs allcmds globaloptions fields getgitrepo progname progde
|
||||||
(cmd, seek, globalconfig) <- parsewith False cmdparser
|
(cmd, seek, globalconfig) <- parsewith False cmdparser
|
||||||
(\a -> inRepo $ a . Just)
|
(\a -> inRepo $ a . Just)
|
||||||
(liftIO . O.handleParseResult)
|
(liftIO . O.handleParseResult)
|
||||||
when (cmdnomessages cmd) $
|
when (cmdnomessages cmd) $ do
|
||||||
Annex.setOutput QuietOutput
|
Annex.setOutput QuietOutput
|
||||||
|
Annex.changeState $ \s -> s
|
||||||
|
{ Annex.output = (Annex.output s) { implicitMessages = False } }
|
||||||
getParsed globalconfig
|
getParsed globalconfig
|
||||||
whenM (annexDebug <$> Annex.getGitConfig) $
|
whenM (annexDebug <$> Annex.getGitConfig) $
|
||||||
liftIO enableDebugOutput
|
liftIO enableDebugOutput
|
||||||
|
|
|
@ -124,7 +124,7 @@ includeCommandAction a = account =<< tryIO (callCommandAction a)
|
||||||
account (Right False) = incerr
|
account (Right False) = incerr
|
||||||
account (Left err) = do
|
account (Left err) = do
|
||||||
toplevelWarning True (show err)
|
toplevelWarning True (show err)
|
||||||
showEndFail
|
implicitMessage showEndFail
|
||||||
incerr
|
incerr
|
||||||
incerr = do
|
incerr = do
|
||||||
Annex.incError
|
Annex.incError
|
||||||
|
@ -146,8 +146,8 @@ callCommandAction' = start
|
||||||
cleanup = stage $ status
|
cleanup = stage $ status
|
||||||
stage = (=<<)
|
stage = (=<<)
|
||||||
skip = return Nothing
|
skip = return Nothing
|
||||||
failure = showEndFail >> return (Just False)
|
failure = implicitMessage showEndFail >> return (Just False)
|
||||||
status r = showEndResult r >> return (Just r)
|
status r = implicitMessage (showEndResult r) >> return (Just r)
|
||||||
|
|
||||||
{- Do concurrent output when that has been requested. -}
|
{- Do concurrent output when that has been requested. -}
|
||||||
allowConcurrentOutput :: Annex a -> Annex a
|
allowConcurrentOutput :: Annex a -> Annex a
|
||||||
|
|
|
@ -66,8 +66,11 @@ withParams mkseek paramdesc = mkseek <$> cmdParams paramdesc
|
||||||
noCommit :: Command -> Command
|
noCommit :: Command -> Command
|
||||||
noCommit c = c { cmdnocommit = True }
|
noCommit c = c { cmdnocommit = True }
|
||||||
|
|
||||||
{- Indicates that a command should not output anything other than what
|
{- Indicates that a command should not output the usual messages when
|
||||||
- it directly sends to stdout. (--json can override this). -}
|
- starting or stopping processing a file or other item. Unless --json mode
|
||||||
|
- is enabled, this also enables quiet output mode, so only things
|
||||||
|
- explicitly output by the command are shown and not progress messages
|
||||||
|
- etc. -}
|
||||||
noMessages :: Command -> Command
|
noMessages :: Command -> Command
|
||||||
noMessages c = c { cmdnomessages = True }
|
noMessages c = c { cmdnomessages = True }
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,11 @@ import qualified Git.Ref
|
||||||
import Git.FilePath
|
import Git.FilePath
|
||||||
|
|
||||||
cmd :: Command
|
cmd :: Command
|
||||||
cmd = notBareRepo $ noCommit $ noMessages $ withGlobalOptions [jsonOption] $
|
cmd = notBareRepo $ noCommit $ noMessages $
|
||||||
command "status" SectionCommon
|
withGlobalOptions [jsonOption] $
|
||||||
"show the working tree status"
|
command "status" SectionCommon
|
||||||
paramPaths (withParams seek)
|
"show the working tree status"
|
||||||
|
paramPaths (withParams seek)
|
||||||
|
|
||||||
seek :: CmdParams -> CommandSeek
|
seek :: CmdParams -> CommandSeek
|
||||||
seek = withWords start
|
seek = withWords start
|
||||||
|
|
|
@ -36,6 +36,7 @@ module Messages (
|
||||||
debugEnabled,
|
debugEnabled,
|
||||||
commandProgressDisabled,
|
commandProgressDisabled,
|
||||||
outputMessage,
|
outputMessage,
|
||||||
|
implicitMessage,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Text.JSON
|
import Text.JSON
|
||||||
|
@ -212,3 +213,9 @@ commandProgressDisabled = withOutputType $ \t -> return $ case t of
|
||||||
JSONOutput -> True
|
JSONOutput -> True
|
||||||
NormalOutput -> False
|
NormalOutput -> False
|
||||||
ConcurrentOutput _ -> True
|
ConcurrentOutput _ -> True
|
||||||
|
|
||||||
|
{- Use to show a message that is displayed implicitly, and so might be
|
||||||
|
- disabled when running a certian command that needs more control over its
|
||||||
|
- output. -}
|
||||||
|
implicitMessage :: Annex () -> Annex ()
|
||||||
|
implicitMessage = whenM (implicitMessages <$> Annex.getState Annex.output)
|
||||||
|
|
|
@ -40,7 +40,7 @@ type CommandCleanup = Annex Bool
|
||||||
data Command = Command
|
data Command = Command
|
||||||
{ cmdcheck :: [CommandCheck] -- check stage
|
{ cmdcheck :: [CommandCheck] -- check stage
|
||||||
, cmdnocommit :: Bool -- don't commit journalled state changes
|
, cmdnocommit :: Bool -- don't commit journalled state changes
|
||||||
, cmdnomessages :: Bool -- don't output normal messages
|
, cmdnomessages :: Bool -- don't output normal messages
|
||||||
, cmdname :: String
|
, cmdname :: String
|
||||||
, cmdparamdesc :: CmdParamsDesc -- description of params for usage
|
, cmdparamdesc :: CmdParamsDesc -- description of params for usage
|
||||||
, cmdsection :: CommandSection
|
, cmdsection :: CommandSection
|
||||||
|
|
|
@ -24,6 +24,7 @@ data SideActionBlock = NoBlock | StartBlock | InBlock
|
||||||
data MessageState = MessageState
|
data MessageState = MessageState
|
||||||
{ outputType :: OutputType
|
{ outputType :: OutputType
|
||||||
, sideActionBlock :: SideActionBlock
|
, sideActionBlock :: SideActionBlock
|
||||||
|
, implicitMessages :: Bool
|
||||||
#ifdef WITH_CONCURRENTOUTPUT
|
#ifdef WITH_CONCURRENTOUTPUT
|
||||||
, consoleRegion :: Maybe ConsoleRegion
|
, consoleRegion :: Maybe ConsoleRegion
|
||||||
, consoleRegionErrFlag :: Bool
|
, consoleRegionErrFlag :: Bool
|
||||||
|
@ -35,6 +36,7 @@ instance Default MessageState
|
||||||
def = MessageState
|
def = MessageState
|
||||||
{ outputType = NormalOutput
|
{ outputType = NormalOutput
|
||||||
, sideActionBlock = NoBlock
|
, sideActionBlock = NoBlock
|
||||||
|
, implicitMessages = True
|
||||||
#ifdef WITH_CONCURRENTOUTPUT
|
#ifdef WITH_CONCURRENTOUTPUT
|
||||||
, consoleRegion = Nothing
|
, consoleRegion = Nothing
|
||||||
, consoleRegionErrFlag = False
|
, consoleRegionErrFlag = False
|
||||||
|
|
Loading…
Reference in a new issue