Make --json and --quiet suppress automatic init messages

And any other messages that might be output before a command starts.

Fixes a reversion introduced in version 5.20150727.

During the optparse-applicative conversion, I needed a place to run
per-command global option setters, and I made it get run during the seek stage. But
that is too late to have --json and --quiet disable output produced in the
check stage. Fix is just to run those per-command global option setters at
the same time as the all-command global option setters.

This commit was sponsored by Thom May.
This commit is contained in:
Joey Hess 2016-09-05 15:32:59 -04:00
parent c9082cf0e4
commit 219e2fa157
No known key found for this signature in database
GPG key ID: C910D9222512E3C7
6 changed files with 21 additions and 14 deletions

View file

@ -6,6 +6,9 @@ git-annex (6.20160809) UNRELEASED; urgency=medium
* examimekey: Allow being run in a git repo that is not initialized by
git-annex yet.
* Android: Fix disabling use of cp --reflink=auto, curl, sha224, and sha384.
* Make --json and --quiet suppress automatic init messages, and any
other messages that might be output before a command starts.
Fixes a reversion introduced in version 5.20150727.
-- Joey Hess <id@joeyh.name> Mon, 05 Sep 2016 11:51:49 -0400

View file

@ -99,7 +99,7 @@ parseCmd progname progdesc globaloptions allargs allcmds getparser =
mkparser c = (,,)
<$> pure c
<*> getparser c
<*> combineGlobalOptions globaloptions
<*> combineGlobalOptions (globaloptions ++ cmdglobaloptions c)
synopsis n d = n ++ " - " ++ d
intro = mconcat $ concatMap (\l -> [H.text l, H.line])
(synopsis progname progdesc : commandList allcmds)

View file

@ -33,7 +33,7 @@ import Types.ActionItem
command :: String -> CommandSection -> String -> CmdParamsDesc -> (CmdParamsDesc -> CommandParser) -> Command
command name section desc paramdesc mkparser =
Command commonChecks False False name paramdesc
section desc (mkparser paramdesc) Nothing
section desc (mkparser paramdesc) [] Nothing
{- Simple option parser that takes all non-option params as-is. -}
withParams :: (CmdParams -> v) -> CmdParamsDesc -> Parser v
@ -68,18 +68,9 @@ noMessages c = c { cmdnomessages = True }
noRepo :: (String -> Parser (IO ())) -> Command -> Command
noRepo a c = c { cmdnorepo = Just (a (cmdparamdesc c)) }
{- Adds global options to a command's option parser, and modifies its seek
- option to first run actions for them.
-}
{- Adds global options to a command's. -}
withGlobalOptions :: [GlobalOption] -> Command -> Command
withGlobalOptions os c = c { cmdparser = apply <$> mixin (cmdparser c) }
where
mixin p = (,)
<$> p
<*> combineGlobalOptions os
apply (seek, globalsetters) = do
void $ getParsed globalsetters
seek
withGlobalOptions os c = c { cmdglobaloptions = cmdglobaloptions c ++ os }
{- For start and perform stages to indicate what step to run next. -}
next :: a -> Annex (Maybe a)

View file

@ -1,6 +1,6 @@
{- git-annex command data types
-
- Copyright 2010-2015 Joey Hess <id@joeyh.name>
- Copyright 2010-2016 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@ -11,6 +11,7 @@ import Data.Ord
import Options.Applicative.Types (Parser)
import Types
import Types.DeferredParse
{- A command runs in these stages.
-
@ -46,6 +47,7 @@ data Command = Command
, cmdsection :: CommandSection
, cmddesc :: String -- description of command for usage
, cmdparser :: CommandParser -- command line parser
, cmdglobaloptions :: [GlobalOption] -- additional global options
, cmdnorepo :: Maybe (Parser (IO ())) -- used when not in a repo
}

View file

@ -38,3 +38,4 @@ I really like git annex and its concepts and I'm currently in the process of add
So far it works very well and it seems like I finally found a scalable and convenient solution to protect all my files and make them accessible from everywhere.
> [[fixed|done]] --[[Joey]]

View file

@ -0,0 +1,10 @@
[[!comment format=mdwn
username="joey"
subject="""comment 1"""
date="2016-09-05T18:44:00Z"
content="""
Hmm, seems that the output happens before it gets around to parsing the
--json, which will disable such outputs.
Probably a reversion introduced with the switch to optparse-applicative.
"""]]