group: Added --list option
authorJoey Hess <joeyh@joeyh.name>
Wed, 29 May 2024 17:37:30 +0000 (13:37 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 29 May 2024 17:37:35 +0000 (13:37 -0400)
Seemed to make sense to exclude groups used only by dead repositories.

CHANGELOG
Command/Group.hs
doc/forum/Feature_request__58___List_all_locations__44___groups__38__wants/comment_4_781a39ea819887335f65a31198220b44._comment
doc/git-annex-group.mdwn

index 4ee02472c320ddcfefcdbacf17c8387861de49c6..cc9ef7f688c2a03b5a9d308d4dd7ab0c86df7df8 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -7,6 +7,7 @@ git-annex (10.20240431) UNRELEASED; urgency=medium
     git-remote-annex.
   * When building an adjusted unlocked branch, make pointer files
     executable when the annex object file is executable.
+  * group: Added --list option.
   * fsck: Fix recent reversion that made it say it was checksumming files
     whose content is not present.
   * Avoid the --fast option preventing checksumming in some cases it
index 41717961a5fef9601a9d024c44c28752aa11a7a8..e01539ff5f21127a2e42074aa6c1c387e007ac8a 100644 (file)
@@ -1,6 +1,6 @@
 {- git-annex command
  -
- - Copyright 2012 Joey Hess <id@joeyh.name>
+ - Copyright 2012-2024 Joey Hess <id@joeyh.name>
  -
  - Licensed under the GNU AGPL version 3 or higher.
  -}
@@ -9,18 +9,38 @@ module Command.Group where
 
 import Command
 import qualified Remote
-import Logs.Group
 import Types.Group
+import Logs.Group
+import Logs.UUID
+import Logs.Trust
 import Utility.SafeOutput
 
 import qualified Data.Set as S
+import qualified Data.Map as M
 
 cmd :: Command
 cmd = noMessages $ command "group" SectionSetup "add a repository to a group"
-       (paramPair paramRemote paramDesc) (withParams seek)
+       (paramPair paramRemote paramDesc) (seek <$$> optParser)
+
+data GroupOptions = GroupOptions
+       { cmdparams :: CmdParams
+       , listOption :: Bool
+       }
 
-seek :: CmdParams -> CommandSeek
-seek = withWords (commandAction . start)
+optParser :: CmdParamsDesc -> Parser GroupOptions
+optParser desc = GroupOptions
+       <$> cmdParams desc
+       <*> switch
+               ( long "list"
+               <> help "list all currently defined groups"
+               )
+
+seek :: GroupOptions -> CommandSeek
+seek o
+       | listOption o = if null (cmdparams o)
+               then commandAction startList
+               else giveup "Cannot combine --list with other options"
+       | otherwise = commandAction $ start (cmdparams o)
 
 start :: [String] -> CommandStart
 start ps@(name:g:[]) = do
@@ -33,12 +53,21 @@ start ps@(name:g:[]) = do
 start (name:[]) = do
        u <- Remote.nameToUUID name
        startingCustomOutput (ActionItemOther Nothing) $ do
-               liftIO . putStrLn . safeOutput . unwords . map fmt . S.toList
-                       =<< lookupGroups u
+               liftIO . listGroups =<< lookupGroups u
                next $ return True
+start _ = giveup "Specify a repository and a group."
+
+startList :: CommandStart
+startList = startingCustomOutput (ActionItemOther Nothing) $ do
+       us <- trustExclude DeadTrusted =<< M.keys <$> uuidDescMap
+       gs <- foldl' S.union mempty <$> mapM lookupGroups us
+       liftIO $ listGroups gs
+       next $ return True
+
+listGroups :: S.Set Group -> IO ()
+listGroups = liftIO . putStrLn . safeOutput . unwords . map fmt . S.toList
   where
        fmt (Group g) = decodeBS g
-start _ = giveup "Specify a repository and a group."
 
 setGroup :: UUID -> Group -> CommandPerform
 setGroup uuid g = do
index 0dda51166979da87de07b1e8a52cd1b55a7139fb..5079a9a2974a3e028679630c77e7119f1dddd86f 100644 (file)
@@ -12,8 +12,8 @@ improvements on querying in this area.
 its preferred content expression, as well as any groupwanted expression,
 and the standard preferred content expression.
 
-There could be a command that just outputs a list of groups, one per line.
-Maybe `git-annex group --list`
+There could be a command that just outputs a list of groups.
+Maybe `git-annex group --list` (update: implemented this)
 
 Then you could get your dump of the groupwanted configurations for each
 group:
index afe5aee47fd828b99541d19cdf9c9274c3dbb191..32dafabee780cead089ce977cb56e7c29a67f8ac 100644 (file)
@@ -8,7 +8,7 @@ git annex group `repository [groupname]`
 
 # DESCRIPTION
 
-Adds a repository to a group, such as "archival", "enduser", or "transfer".
+Adds a repository to a group, such as "archive" or "transfer".
 The groupname must be a single word.
   
 Omit the groupname to show the current groups that a repository is in.
@@ -20,7 +20,11 @@ A repository can be in multiple groups at the same time.
 
 # OPTIONS
 
-* The [[git-annex-common-options]](1) can be used.
+* `--list`
+
+  Outputs a list of all groups that are used by at least one repository.
+
+* Also the [[git-annex-common-options]](1) can be used.
 
 # SEE ALSO