make query commands not output extraneous messages
config group groupwanted numcopies schedule wanted required: Avoid displaying extraneous messages about repository auto-init, git-annex branch merging, etc, when being used to get information.
This commit is contained in:
parent
baa2ab2c7d
commit
d0651bb567
10 changed files with 51 additions and 15 deletions
|
@ -12,6 +12,9 @@ git-annex (6.20170215) UNRELEASED; urgency=medium
|
|||
* sync: Improve integration with receive.denyCurrentBranch=updateInstead,
|
||||
displaying error messages from the remote then it fails to update
|
||||
its checked out branch.
|
||||
* config group groupwanted numcopies schedule wanted required:
|
||||
Avoid displaying extraneous messages about repository auto-init,
|
||||
git-annex branch merging, etc, when being used to get information.
|
||||
|
||||
-- Joey Hess <id@joeyh.name> Tue, 14 Feb 2017 15:54:25 -0400
|
||||
|
||||
|
|
12
Command.hs
12
Command.hs
|
@ -22,12 +22,14 @@ import CmdLine.GlobalSetter as ReExported
|
|||
import CmdLine.GitAnnex.Options as ReExported
|
||||
import CmdLine.Batch as ReExported
|
||||
import Options.Applicative as ReExported hiding (command)
|
||||
import qualified Annex
|
||||
import qualified Git
|
||||
import Annex.Init
|
||||
import Config
|
||||
import Utility.Daemon
|
||||
import Types.Transfer
|
||||
import Types.ActionItem
|
||||
import Types.Messages
|
||||
|
||||
{- Generates a normal Command -}
|
||||
command :: String -> CommandSection -> String -> CmdParamsDesc -> (CmdParamsDesc -> CommandParser) -> Command
|
||||
|
@ -63,6 +65,16 @@ noCommit c = c { cmdnocommit = True }
|
|||
noMessages :: Command -> Command
|
||||
noMessages c = c { cmdnomessages = True }
|
||||
|
||||
{- Undoes noMessages -}
|
||||
allowMessages :: Annex ()
|
||||
allowMessages = do
|
||||
curr <- Annex.getState Annex.output
|
||||
case outputType curr of
|
||||
QuietOutput -> Annex.setOutput NormalOutput
|
||||
_ -> noop
|
||||
Annex.changeState $ \s -> s
|
||||
{ Annex.output = (Annex.output s) { implicitMessages = True } }
|
||||
|
||||
{- Adds a fallback action to a command, that will be run if it's used
|
||||
- outside a git repository. -}
|
||||
noRepo :: (String -> Parser (IO ())) -> Command -> Command
|
||||
|
|
|
@ -11,7 +11,8 @@ import Command
|
|||
import Logs.Config
|
||||
|
||||
cmd :: Command
|
||||
cmd = command "config" SectionSetup "configuration stored in git-annex branch"
|
||||
cmd = noMessages $ command "config" SectionSetup
|
||||
"configuration stored in git-annex branch"
|
||||
paramNothing (seek <$$> optParser)
|
||||
|
||||
data Action
|
||||
|
@ -47,11 +48,13 @@ optParser _ = setconfig <|> getconfig <|> unsetconfig
|
|||
|
||||
seek :: Action -> CommandSeek
|
||||
seek (SetConfig name val) = commandAction $ do
|
||||
allowMessages
|
||||
showStart name val
|
||||
next $ next $ do
|
||||
setGlobalConfig name val
|
||||
return True
|
||||
seek (UnsetConfig name) = commandAction $ do
|
||||
allowMessages
|
||||
showStart name "unset"
|
||||
next $ next $ do
|
||||
unsetGlobalConfig name
|
||||
|
|
|
@ -15,7 +15,7 @@ import Types.Group
|
|||
import qualified Data.Set as S
|
||||
|
||||
cmd :: Command
|
||||
cmd = command "group" SectionSetup "add a repository to a group"
|
||||
cmd = noMessages $ command "group" SectionSetup "add a repository to a group"
|
||||
(paramPair paramRemote paramDesc) (withParams seek)
|
||||
|
||||
seek :: CmdParams -> CommandSeek
|
||||
|
@ -23,12 +23,13 @@ seek = withWords start
|
|||
|
||||
start :: [String] -> CommandStart
|
||||
start (name:g:[]) = do
|
||||
allowMessages
|
||||
showStart "group" name
|
||||
u <- Remote.nameToUUID name
|
||||
next $ setGroup u g
|
||||
start (name:[]) = do
|
||||
u <- Remote.nameToUUID name
|
||||
showRaw . unwords . S.toList =<< lookupGroups u
|
||||
liftIO . putStrLn . unwords . S.toList =<< lookupGroups u
|
||||
stop
|
||||
start _ = giveup "Specify a repository and a group."
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import Logs.PreferredContent
|
|||
import Command.Wanted (performGet, performSet)
|
||||
|
||||
cmd :: Command
|
||||
cmd = command "groupwanted" SectionSetup
|
||||
cmd = noMessages $ command "groupwanted" SectionSetup
|
||||
"get or set groupwanted expression"
|
||||
(paramPair paramGroup (paramOptional paramExpression))
|
||||
(withParams seek)
|
||||
|
@ -23,6 +23,7 @@ seek = withWords start
|
|||
start :: [String] -> CommandStart
|
||||
start (g:[]) = next $ performGet groupPreferredContentMapRaw g
|
||||
start (g:expr:[]) = do
|
||||
allowMessages
|
||||
showStart "groupwanted" g
|
||||
next $ performSet groupPreferredContentSet expr g
|
||||
start _ = giveup "Specify a group."
|
||||
|
|
|
@ -10,10 +10,9 @@ module Command.NumCopies where
|
|||
import Command
|
||||
import qualified Annex
|
||||
import Annex.NumCopies
|
||||
import Types.Messages
|
||||
|
||||
cmd :: Command
|
||||
cmd = command "numcopies" SectionSetup
|
||||
cmd = noMessages $ command "numcopies" SectionSetup
|
||||
"configure desired number of copies"
|
||||
paramNumber (withParams seek)
|
||||
|
||||
|
@ -35,7 +34,6 @@ start _ = giveup "Specify a single number."
|
|||
|
||||
startGet :: CommandStart
|
||||
startGet = next $ next $ do
|
||||
Annex.setOutput QuietOutput
|
||||
v <- getGlobalNumCopies
|
||||
case v of
|
||||
Just n -> liftIO $ putStrLn $ show $ fromNumCopies n
|
||||
|
@ -49,6 +47,7 @@ startGet = next $ next $ do
|
|||
|
||||
startSet :: Int -> CommandStart
|
||||
startSet n = do
|
||||
allowMessages
|
||||
showStart "numcopies" (show n)
|
||||
next $ next $ do
|
||||
setGlobalNumCopies $ NumCopies n
|
||||
|
|
|
@ -8,16 +8,14 @@
|
|||
module Command.Schedule where
|
||||
|
||||
import Command
|
||||
import qualified Annex
|
||||
import qualified Remote
|
||||
import Logs.Schedule
|
||||
import Types.ScheduledActivity
|
||||
import Types.Messages
|
||||
|
||||
import qualified Data.Set as S
|
||||
|
||||
cmd :: Command
|
||||
cmd = command "schedule" SectionSetup "get or set scheduled jobs"
|
||||
cmd = noMessages $ command "schedule" SectionSetup "get or set scheduled jobs"
|
||||
(paramPair paramRemote (paramOptional paramExpression))
|
||||
(withParams seek)
|
||||
|
||||
|
@ -29,6 +27,7 @@ start = parse
|
|||
where
|
||||
parse (name:[]) = go name performGet
|
||||
parse (name:expr:[]) = go name $ \uuid -> do
|
||||
allowMessages
|
||||
showStart "schedule" name
|
||||
performSet expr uuid
|
||||
parse _ = giveup "Specify a repository."
|
||||
|
@ -39,7 +38,6 @@ start = parse
|
|||
|
||||
performGet :: UUID -> CommandPerform
|
||||
performGet uuid = do
|
||||
Annex.setOutput QuietOutput
|
||||
s <- scheduleGet uuid
|
||||
liftIO $ putStrLn $ intercalate "; " $
|
||||
map fromScheduledActivity $ S.toList s
|
||||
|
|
|
@ -8,10 +8,8 @@
|
|||
module Command.Wanted where
|
||||
|
||||
import Command
|
||||
import qualified Annex
|
||||
import qualified Remote
|
||||
import Logs.PreferredContent
|
||||
import Types.Messages
|
||||
import Types.StandardGroups
|
||||
|
||||
import qualified Data.Map as M
|
||||
|
@ -27,7 +25,8 @@ cmd'
|
|||
-> Annex (M.Map UUID PreferredContentExpression)
|
||||
-> (UUID -> PreferredContentExpression -> Annex ())
|
||||
-> Command
|
||||
cmd' name desc getter setter = command name SectionSetup desc pdesc (withParams seek)
|
||||
cmd' name desc getter setter = noMessages $
|
||||
command name SectionSetup desc pdesc (withParams seek)
|
||||
where
|
||||
pdesc = paramPair paramRemote (paramOptional paramExpression)
|
||||
|
||||
|
@ -35,6 +34,7 @@ cmd' name desc getter setter = command name SectionSetup desc pdesc (withParams
|
|||
|
||||
start (rname:[]) = go rname (performGet getter)
|
||||
start (rname:expr:[]) = go rname $ \uuid -> do
|
||||
allowMessages
|
||||
showStart name rname
|
||||
performSet setter expr uuid
|
||||
start _ = giveup "Specify a repository."
|
||||
|
@ -45,7 +45,6 @@ cmd' name desc getter setter = command name SectionSetup desc pdesc (withParams
|
|||
|
||||
performGet :: Ord a => Annex (M.Map a PreferredContentExpression) -> a -> CommandPerform
|
||||
performGet getter a = do
|
||||
Annex.setOutput QuietOutput
|
||||
m <- getter
|
||||
liftIO $ putStrLn $ fromMaybe "" $ M.lookup a m
|
||||
next $ return True
|
||||
|
|
|
@ -9,3 +9,5 @@ not metadata=distribution-restrictions=*
|
|||
so it is necessary to avoid considering all the merging and recording messages, complicating using wanted in the scripts etc
|
||||
|
||||
[[!meta author=yoh]]
|
||||
|
||||
> [[fixed|done]] --[[Joey]]
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
[[!comment format=mdwn
|
||||
username="joey"
|
||||
subject="""comment 3"""
|
||||
date="2017-02-16T16:53:30Z"
|
||||
content="""
|
||||
This can happen at other times than repository auto-init too.
|
||||
|
||||
Generally plumbing commands just turn off all such messages very early,
|
||||
but in this case, the command has one mode where it's supposed to get data,
|
||||
which is plumbing-like, and another mode where it sets data, which is
|
||||
supposed to display normal messages about what it's doing. So it didn't
|
||||
turn messages off until after parsing the command line, which is too late.
|
||||
|
||||
Affected commands: config group groupwanted numcopies schedule wanted required
|
||||
|
||||
Fairly sure that's a complete set, at least it's all the commands with
|
||||
both a get and a set mode.
|
||||
"""]]
|
Loading…
Reference in a new issue