added an option to the groups command to return only unreferenced groups
Change-Id: Id7ece9206d9da97d45725233e02051fc3967c2ee
diff --git a/cli/src/main/java/org/onosproject/cli/net/GroupsListCommand.java b/cli/src/main/java/org/onosproject/cli/net/GroupsListCommand.java
index faa2257..58b0903 100644
--- a/cli/src/main/java/org/onosproject/cli/net/GroupsListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/GroupsListCommand.java
@@ -84,6 +84,11 @@
@Completion(GroupTypeCompleter.class)
private String type = null;
+ @Option(name = "-u", aliases = "--unreferenced",
+ description = "Print unreferenced groups only",
+ required = false, multiValued = false)
+ private boolean unreferencedOnly = false;
+
private JsonNode json(Map<Device, List<Group>> sortedGroups) {
ArrayNode result = mapper().createArrayNode();
@@ -101,6 +106,12 @@
GroupService groupService = get(GroupService.class);
SortedMap<Device, List<Group>> sortedGroups =
getSortedGroups(deviceService, groupService);
+
+ if (referencedOnly && unreferencedOnly) {
+ print("Options -r and -u cannot be used at the same time");
+ return;
+ }
+
if (outputJson()) {
print("%s", json(sortedGroups));
} else {
@@ -137,6 +148,9 @@
groupStream = groupStream.filter(g ->
g.type().equals(GroupDescription.Type.valueOf(type.toUpperCase())));
}
+ if (unreferencedOnly) {
+ groupStream = groupStream.filter(g -> g.referenceCount() == 0);
+ }
sortedGroups.put(d, groupStream.sorted(Comparators.GROUP_COMPARATOR).collect(Collectors.toList()));
}
return sortedGroups;