summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-02-16 13:24:16 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-02-16 13:24:35 -0400
commit34bcff4cba4a8f866110309ae00bcd4a8deb7551 (patch)
treea187a962bb859d8a77ef59c459e5cc2ace0dd795
parentb65b8fe7f1b63403e8b1fd1e149e0adb5b00277d (diff)
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.
-rw-r--r--CHANGELOG3
-rw-r--r--Command.hs12
-rw-r--r--Command/Config.hs5
-rw-r--r--Command/Group.hs5
-rw-r--r--Command/GroupWanted.hs3
-rw-r--r--Command/NumCopies.hs5
-rw-r--r--Command/Schedule.hs6
-rw-r--r--Command/Wanted.hs7
-rw-r--r--doc/todo/output_of_wanted___40__and_possibly_group_etc__41___should_not_be_polluted_with___34__informational__34___messages.mdwn2
-rw-r--r--doc/todo/output_of_wanted___40__and_possibly_group_etc__41___should_not_be_polluted_with___34__informational__34___messages/comment_3_e006b8efab713d4965316c9846ec437c._comment18
10 files changed, 51 insertions, 15 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 456b12981..f5c0f3ce5 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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
diff --git a/Command.hs b/Command.hs
index f8d4fe32b..58f57762e 100644
--- a/Command.hs
+++ b/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
diff --git a/Command/Config.hs b/Command/Config.hs
index 690c8d288..c9b6a7b0b 100644
--- a/Command/Config.hs
+++ b/Command/Config.hs
@@ -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
diff --git a/Command/Group.hs b/Command/Group.hs
index 6d9b4ab13..65e062589 100644
--- a/Command/Group.hs
+++ b/Command/Group.hs
@@ -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."
diff --git a/Command/GroupWanted.hs b/Command/GroupWanted.hs
index c0be2462d..939b3030a 100644
--- a/Command/GroupWanted.hs
+++ b/Command/GroupWanted.hs
@@ -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."
diff --git a/Command/NumCopies.hs b/Command/NumCopies.hs
index 005a0d16a..9e467da7a 100644
--- a/Command/NumCopies.hs
+++ b/Command/NumCopies.hs
@@ -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
diff --git a/Command/Schedule.hs b/Command/Schedule.hs
index c9d4f915f..5814d99f1 100644
--- a/Command/Schedule.hs
+++ b/Command/Schedule.hs
@@ -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
diff --git a/Command/Wanted.hs b/Command/Wanted.hs
index 8fd369df6..fc1fa86bd 100644
--- a/Command/Wanted.hs
+++ b/Command/Wanted.hs
@@ -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
diff --git a/doc/todo/output_of_wanted___40__and_possibly_group_etc__41___should_not_be_polluted_with___34__informational__34___messages.mdwn b/doc/todo/output_of_wanted___40__and_possibly_group_etc__41___should_not_be_polluted_with___34__informational__34___messages.mdwn
index 0dd6a9702..b2849f3f1 100644
--- a/doc/todo/output_of_wanted___40__and_possibly_group_etc__41___should_not_be_polluted_with___34__informational__34___messages.mdwn
+++ b/doc/todo/output_of_wanted___40__and_possibly_group_etc__41___should_not_be_polluted_with___34__informational__34___messages.mdwn
@@ -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]]
diff --git a/doc/todo/output_of_wanted___40__and_possibly_group_etc__41___should_not_be_polluted_with___34__informational__34___messages/comment_3_e006b8efab713d4965316c9846ec437c._comment b/doc/todo/output_of_wanted___40__and_possibly_group_etc__41___should_not_be_polluted_with___34__informational__34___messages/comment_3_e006b8efab713d4965316c9846ec437c._comment
new file mode 100644
index 000000000..7174ab82a
--- /dev/null
+++ b/doc/todo/output_of_wanted___40__and_possibly_group_etc__41___should_not_be_polluted_with___34__informational__34___messages/comment_3_e006b8efab713d4965316c9846ec437c._comment
@@ -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.
+"""]]