]> nmode's Git Repositories - signal-cli/commitdiff
Added new parameter to filter the output of listGroups by groupId
authorAsamK <asamk@gmx.de>
Mon, 16 May 2022 13:22:03 +0000 (15:22 +0200)
committerAsamK <asamk@gmx.de>
Mon, 16 May 2022 13:22:03 +0000 (15:22 +0200)
Fixes #953

man/signal-cli.1.adoc
src/main/java/org/asamk/signal/commands/ListGroupsCommand.java

index 7bbdbf323da454ecf442f0e935a7708650346cde..4fdd684a86e361a6b67b24fcfc3d780876ee3e26 100644 (file)
@@ -413,6 +413,9 @@ In json mode this is outputted as an list of objects and is always in detailed m
 *-d*, *--detailed*::
 Include the list of members of each group and the group invite link.
 
+*-g*, *--group-id*::
+Filter the group list by one or more group IDs.
+
 === listContacts
 
 Show a list of known contacts with names.
index 80e583af7318bec1f8b6af95e12901b007cef46c..c08571f7e599d35ba2a5272e034a9ae6aed3ed73 100644 (file)
@@ -11,6 +11,7 @@ import org.asamk.signal.manager.storage.recipients.RecipientAddress;
 import org.asamk.signal.output.JsonWriter;
 import org.asamk.signal.output.OutputWriter;
 import org.asamk.signal.output.PlainTextWriter;
+import org.asamk.signal.util.CommandUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -33,6 +34,7 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
         subparser.addArgument("-d", "--detailed")
                 .action(Arguments.storeTrue())
                 .help("List the members and group invite links of each group. If output=json, then this is always set");
+        subparser.addArgument("-g", "--group-id").help("Specify one or more group IDs to show.").nargs("*");
     }
 
     private static Set<String> resolveMembers(Set<RecipientAddress> addresses) {
@@ -79,7 +81,13 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
     public void handleCommand(
             final Namespace ns, final Manager m, final OutputWriter outputWriter
     ) throws CommandException {
-        final var groups = m.getGroups();
+        var groups = m.getGroups();
+
+        final var groupIdStrings = ns.<String>getList("group-id");
+        final var groupIds = CommandUtil.getGroupIds(groupIdStrings);
+        if (groupIds.size() > 0) {
+            groups = groups.stream().filter(g -> groupIds.contains(g.groupId())).toList();
+        }
 
         if (outputWriter instanceof JsonWriter jsonWriter) {