From 1a5415ba53e2c231eef4801a928a175ca7fe4c1f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 5 Sep 2016 15:32:59 -0400 Subject: 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. --- CHANGELOG | 3 +++ CmdLine.hs | 2 +- Command.hs | 15 +++------------ Types/Command.hs | 4 +++- ...-fast_outputs_text_in_addition_to_the_json_string.mdwn | 1 + .../comment_1_fa80da021e6a1d1ab5e138199d83f1d2._comment | 10 ++++++++++ 6 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 doc/bugs/git_annex_info_--json_--fast_outputs_text_in_addition_to_the_json_string/comment_1_fa80da021e6a1d1ab5e138199d83f1d2._comment diff --git a/CHANGELOG b/CHANGELOG index dad55baf4..8d9abccf8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 Mon, 05 Sep 2016 11:51:49 -0400 diff --git a/CmdLine.hs b/CmdLine.hs index 1c9ee7f90..c9de90ec0 100644 --- a/CmdLine.hs +++ b/CmdLine.hs @@ -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) diff --git a/Command.hs b/Command.hs index 4ffc7c319..94a474257 100644 --- a/Command.hs +++ b/Command.hs @@ -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) diff --git a/Types/Command.hs b/Types/Command.hs index aa22143dd..baf4934e4 100644 --- a/Types/Command.hs +++ b/Types/Command.hs @@ -1,6 +1,6 @@ {- git-annex command data types - - - Copyright 2010-2015 Joey Hess + - Copyright 2010-2016 Joey Hess - - 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 } diff --git a/doc/bugs/git_annex_info_--json_--fast_outputs_text_in_addition_to_the_json_string.mdwn b/doc/bugs/git_annex_info_--json_--fast_outputs_text_in_addition_to_the_json_string.mdwn index eb8a1ab90..5ef39d525 100644 --- a/doc/bugs/git_annex_info_--json_--fast_outputs_text_in_addition_to_the_json_string.mdwn +++ b/doc/bugs/git_annex_info_--json_--fast_outputs_text_in_addition_to_the_json_string.mdwn @@ -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]] diff --git a/doc/bugs/git_annex_info_--json_--fast_outputs_text_in_addition_to_the_json_string/comment_1_fa80da021e6a1d1ab5e138199d83f1d2._comment b/doc/bugs/git_annex_info_--json_--fast_outputs_text_in_addition_to_the_json_string/comment_1_fa80da021e6a1d1ab5e138199d83f1d2._comment new file mode 100644 index 000000000..841ce613d --- /dev/null +++ b/doc/bugs/git_annex_info_--json_--fast_outputs_text_in_addition_to_the_json_string/comment_1_fa80da021e6a1d1ab5e138199d83f1d2._comment @@ -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. +"""]] -- cgit v1.2.3