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,
|
* sync: Improve integration with receive.denyCurrentBranch=updateInstead,
|
||||||
displaying error messages from the remote then it fails to update
|
displaying error messages from the remote then it fails to update
|
||||||
its checked out branch.
|
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
|
-- 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.GitAnnex.Options as ReExported
|
||||||
import CmdLine.Batch as ReExported
|
import CmdLine.Batch as ReExported
|
||||||
import Options.Applicative as ReExported hiding (command)
|
import Options.Applicative as ReExported hiding (command)
|
||||||
|
import qualified Annex
|
||||||
import qualified Git
|
import qualified Git
|
||||||
import Annex.Init
|
import Annex.Init
|
||||||
import Config
|
import Config
|
||||||
import Utility.Daemon
|
import Utility.Daemon
|
||||||
import Types.Transfer
|
import Types.Transfer
|
||||||
import Types.ActionItem
|
import Types.ActionItem
|
||||||
|
import Types.Messages
|
||||||
|
|
||||||
{- Generates a normal Command -}
|
{- Generates a normal Command -}
|
||||||
command :: String -> CommandSection -> String -> CmdParamsDesc -> (CmdParamsDesc -> CommandParser) -> Command
|
command :: String -> CommandSection -> String -> CmdParamsDesc -> (CmdParamsDesc -> CommandParser) -> Command
|
||||||
|
@ -63,6 +65,16 @@ noCommit c = c { cmdnocommit = True }
|
||||||
noMessages :: Command -> Command
|
noMessages :: Command -> Command
|
||||||
noMessages c = c { cmdnomessages = True }
|
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
|
{- Adds a fallback action to a command, that will be run if it's used
|
||||||
- outside a git repository. -}
|
- outside a git repository. -}
|
||||||
noRepo :: (String -> Parser (IO ())) -> Command -> Command
|
noRepo :: (String -> Parser (IO ())) -> Command -> Command
|
||||||
|
|
|
@ -11,7 +11,8 @@ import Command
|
||||||
import Logs.Config
|
import Logs.Config
|
||||||
|
|
||||||
cmd :: Command
|
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)
|
paramNothing (seek <$$> optParser)
|
||||||
|
|
||||||
data Action
|
data Action
|
||||||
|
@ -47,11 +48,13 @@ optParser _ = setconfig <|> getconfig <|> unsetconfig
|
||||||
|
|
||||||
seek :: Action -> CommandSeek
|
seek :: Action -> CommandSeek
|
||||||
seek (SetConfig name val) = commandAction $ do
|
seek (SetConfig name val) = commandAction $ do
|
||||||
|
allowMessages
|
||||||
showStart name val
|
showStart name val
|
||||||
next $ next $ do
|
next $ next $ do
|
||||||
setGlobalConfig name val
|
setGlobalConfig name val
|
||||||
return True
|
return True
|
||||||
seek (UnsetConfig name) = commandAction $ do
|
seek (UnsetConfig name) = commandAction $ do
|
||||||
|
allowMessages
|
||||||
showStart name "unset"
|
showStart name "unset"
|
||||||
next $ next $ do
|
next $ next $ do
|
||||||
unsetGlobalConfig name
|
unsetGlobalConfig name
|
||||||
|
|
|
@ -15,7 +15,7 @@ import Types.Group
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
|
|
||||||
cmd :: Command
|
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)
|
(paramPair paramRemote paramDesc) (withParams seek)
|
||||||
|
|
||||||
seek :: CmdParams -> CommandSeek
|
seek :: CmdParams -> CommandSeek
|
||||||
|
@ -23,12 +23,13 @@ seek = withWords start
|
||||||
|
|
||||||
start :: [String] -> CommandStart
|
start :: [String] -> CommandStart
|
||||||
start (name:g:[]) = do
|
start (name:g:[]) = do
|
||||||
|
allowMessages
|
||||||
showStart "group" name
|
showStart "group" name
|
||||||
u <- Remote.nameToUUID name
|
u <- Remote.nameToUUID name
|
||||||
next $ setGroup u g
|
next $ setGroup u g
|
||||||
start (name:[]) = do
|
start (name:[]) = do
|
||||||
u <- Remote.nameToUUID name
|
u <- Remote.nameToUUID name
|
||||||
showRaw . unwords . S.toList =<< lookupGroups u
|
liftIO . putStrLn . unwords . S.toList =<< lookupGroups u
|
||||||
stop
|
stop
|
||||||
start _ = giveup "Specify a repository and a group."
|
start _ = giveup "Specify a repository and a group."
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import Logs.PreferredContent
|
||||||
import Command.Wanted (performGet, performSet)
|
import Command.Wanted (performGet, performSet)
|
||||||
|
|
||||||
cmd :: Command
|
cmd :: Command
|
||||||
cmd = command "groupwanted" SectionSetup
|
cmd = noMessages $ command "groupwanted" SectionSetup
|
||||||
"get or set groupwanted expression"
|
"get or set groupwanted expression"
|
||||||
(paramPair paramGroup (paramOptional paramExpression))
|
(paramPair paramGroup (paramOptional paramExpression))
|
||||||
(withParams seek)
|
(withParams seek)
|
||||||
|
@ -23,6 +23,7 @@ seek = withWords start
|
||||||
start :: [String] -> CommandStart
|
start :: [String] -> CommandStart
|
||||||
start (g:[]) = next $ performGet groupPreferredContentMapRaw g
|
start (g:[]) = next $ performGet groupPreferredContentMapRaw g
|
||||||
start (g:expr:[]) = do
|
start (g:expr:[]) = do
|
||||||
|
allowMessages
|
||||||
showStart "groupwanted" g
|
showStart "groupwanted" g
|
||||||
next $ performSet groupPreferredContentSet expr g
|
next $ performSet groupPreferredContentSet expr g
|
||||||
start _ = giveup "Specify a group."
|
start _ = giveup "Specify a group."
|
||||||
|
|
|
@ -10,10 +10,9 @@ module Command.NumCopies where
|
||||||
import Command
|
import Command
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
import Annex.NumCopies
|
import Annex.NumCopies
|
||||||
import Types.Messages
|
|
||||||
|
|
||||||
cmd :: Command
|
cmd :: Command
|
||||||
cmd = command "numcopies" SectionSetup
|
cmd = noMessages $ command "numcopies" SectionSetup
|
||||||
"configure desired number of copies"
|
"configure desired number of copies"
|
||||||
paramNumber (withParams seek)
|
paramNumber (withParams seek)
|
||||||
|
|
||||||
|
@ -35,7 +34,6 @@ start _ = giveup "Specify a single number."
|
||||||
|
|
||||||
startGet :: CommandStart
|
startGet :: CommandStart
|
||||||
startGet = next $ next $ do
|
startGet = next $ next $ do
|
||||||
Annex.setOutput QuietOutput
|
|
||||||
v <- getGlobalNumCopies
|
v <- getGlobalNumCopies
|
||||||
case v of
|
case v of
|
||||||
Just n -> liftIO $ putStrLn $ show $ fromNumCopies n
|
Just n -> liftIO $ putStrLn $ show $ fromNumCopies n
|
||||||
|
@ -49,6 +47,7 @@ startGet = next $ next $ do
|
||||||
|
|
||||||
startSet :: Int -> CommandStart
|
startSet :: Int -> CommandStart
|
||||||
startSet n = do
|
startSet n = do
|
||||||
|
allowMessages
|
||||||
showStart "numcopies" (show n)
|
showStart "numcopies" (show n)
|
||||||
next $ next $ do
|
next $ next $ do
|
||||||
setGlobalNumCopies $ NumCopies n
|
setGlobalNumCopies $ NumCopies n
|
||||||
|
|
|
@ -8,16 +8,14 @@
|
||||||
module Command.Schedule where
|
module Command.Schedule where
|
||||||
|
|
||||||
import Command
|
import Command
|
||||||
import qualified Annex
|
|
||||||
import qualified Remote
|
import qualified Remote
|
||||||
import Logs.Schedule
|
import Logs.Schedule
|
||||||
import Types.ScheduledActivity
|
import Types.ScheduledActivity
|
||||||
import Types.Messages
|
|
||||||
|
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
|
|
||||||
cmd :: Command
|
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))
|
(paramPair paramRemote (paramOptional paramExpression))
|
||||||
(withParams seek)
|
(withParams seek)
|
||||||
|
|
||||||
|
@ -29,6 +27,7 @@ start = parse
|
||||||
where
|
where
|
||||||
parse (name:[]) = go name performGet
|
parse (name:[]) = go name performGet
|
||||||
parse (name:expr:[]) = go name $ \uuid -> do
|
parse (name:expr:[]) = go name $ \uuid -> do
|
||||||
|
allowMessages
|
||||||
showStart "schedule" name
|
showStart "schedule" name
|
||||||
performSet expr uuid
|
performSet expr uuid
|
||||||
parse _ = giveup "Specify a repository."
|
parse _ = giveup "Specify a repository."
|
||||||
|
@ -39,7 +38,6 @@ start = parse
|
||||||
|
|
||||||
performGet :: UUID -> CommandPerform
|
performGet :: UUID -> CommandPerform
|
||||||
performGet uuid = do
|
performGet uuid = do
|
||||||
Annex.setOutput QuietOutput
|
|
||||||
s <- scheduleGet uuid
|
s <- scheduleGet uuid
|
||||||
liftIO $ putStrLn $ intercalate "; " $
|
liftIO $ putStrLn $ intercalate "; " $
|
||||||
map fromScheduledActivity $ S.toList s
|
map fromScheduledActivity $ S.toList s
|
||||||
|
|
|
@ -8,10 +8,8 @@
|
||||||
module Command.Wanted where
|
module Command.Wanted where
|
||||||
|
|
||||||
import Command
|
import Command
|
||||||
import qualified Annex
|
|
||||||
import qualified Remote
|
import qualified Remote
|
||||||
import Logs.PreferredContent
|
import Logs.PreferredContent
|
||||||
import Types.Messages
|
|
||||||
import Types.StandardGroups
|
import Types.StandardGroups
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
|
@ -27,7 +25,8 @@ cmd'
|
||||||
-> Annex (M.Map UUID PreferredContentExpression)
|
-> Annex (M.Map UUID PreferredContentExpression)
|
||||||
-> (UUID -> PreferredContentExpression -> Annex ())
|
-> (UUID -> PreferredContentExpression -> Annex ())
|
||||||
-> Command
|
-> 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
|
where
|
||||||
pdesc = paramPair paramRemote (paramOptional paramExpression)
|
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:[]) = go rname (performGet getter)
|
||||||
start (rname:expr:[]) = go rname $ \uuid -> do
|
start (rname:expr:[]) = go rname $ \uuid -> do
|
||||||
|
allowMessages
|
||||||
showStart name rname
|
showStart name rname
|
||||||
performSet setter expr uuid
|
performSet setter expr uuid
|
||||||
start _ = giveup "Specify a repository."
|
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 :: Ord a => Annex (M.Map a PreferredContentExpression) -> a -> CommandPerform
|
||||||
performGet getter a = do
|
performGet getter a = do
|
||||||
Annex.setOutput QuietOutput
|
|
||||||
m <- getter
|
m <- getter
|
||||||
liftIO $ putStrLn $ fromMaybe "" $ M.lookup a m
|
liftIO $ putStrLn $ fromMaybe "" $ M.lookup a m
|
||||||
next $ return True
|
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
|
so it is necessary to avoid considering all the merging and recording messages, complicating using wanted in the scripts etc
|
||||||
|
|
||||||
[[!meta author=yoh]]
|
[[!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