rreddy-22 commented on code in PR #15150:
URL: https://github.com/apache/kafka/pull/15150#discussion_r1482168707


##########
core/src/main/scala/kafka/admin/ConsumerGroupCommand.scala:
##########
@@ -187,16 +197,69 @@ object ConsumerGroupCommand extends Logging {
     }
 
     def listGroups(): Unit = {
-      if (opts.options.has(opts.stateOpt)) {
-        val stateValue = opts.options.valueOf(opts.stateOpt)
-        val states = if (stateValue == null || stateValue.isEmpty)
-          Set[ConsumerGroupState]()
-        else
-          consumerGroupStatesFromString(stateValue)
-        val listings = listConsumerGroupsWithState(states)
-        printGroupStates(listings.map(e => (e.groupId, e.state.get.toString)))
-      } else
+      val includeState = opts.options.has(opts.stateOpt)
+      val includeType = opts.options.has(opts.typeOpt)
+
+      val groupInfoMap = mutable.Map[String, (String, String)]()
+
+      if (includeType || includeState) {
+        val states = getStateValues()
+        val types = getTypeValues()
+        val listings = {
+          listConsumerGroupsWithFilters(states, types)
+        }
+
+        listings.foreach { listing =>
+          val groupId = listing.groupId
+          val groupType = 
listing.groupType().orElse(ConsumerGroupType.UNKNOWN).toString
+          val state = 
listing.state().orElse(ConsumerGroupState.UNKNOWN).toString
+          groupInfoMap.update(groupId, (state, groupType))
+        }
+
+        val groupInfoList = groupInfoMap.toList.map { case (groupId, (state, 
groupType)) => (groupId, state, groupType) }
+        printGroupInfo(groupInfoList, includeState, includeType)
+
+      } else {
         listConsumerGroups().foreach(println(_))
+      }
+    }
+
+    private def getStateValues(): Set[ConsumerGroupState] = {
+      val stateValue = opts.options.valueOf(opts.stateOpt)
+      if (stateValue == null || stateValue.isEmpty)
+        Set[ConsumerGroupState]()
+      else
+        consumerGroupStatesFromString(stateValue)
+    }
+
+    private def getTypeValues(): Set[ConsumerGroupType] = {
+      val typeValue = opts.options.valueOf(opts.typeOpt)
+      if (typeValue == null || typeValue.isEmpty)
+        Set[ConsumerGroupType]()
+      else
+        consumerGroupTypesFromString(typeValue)
+    }
+
+    private def printGroupInfo(groupsAndInfo: List[(String, String, String)], 
includeState: Boolean, includeType: Boolean): Unit = {
+      val maxGroupLen: Int = groupsAndInfo.foldLeft(15)((maxLen, group) => 
Math.max(maxLen, group._1.length))
+      var header = "GROUP"

Review Comment:
   ahh okie that makes sense!
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to