Add option to sort application by name

Change-Id: I81bac9d164a86ea218cf8ad0140fe6c422a45487
diff --git a/cli/src/main/java/org/onosproject/cli/app/ApplicationsListCommand.java b/cli/src/main/java/org/onosproject/cli/app/ApplicationsListCommand.java
index 3299d33..9b2fb2a 100644
--- a/cli/src/main/java/org/onosproject/cli/app/ApplicationsListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/app/ApplicationsListCommand.java
@@ -17,6 +17,7 @@
 
 import java.net.URI;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 import org.apache.karaf.shell.commands.Command;
@@ -55,12 +56,19 @@
             required = false, multiValued = false)
     private boolean activeOnly = false;
 
+    @Option(name = "-n", aliases = "--name", description = "Sort by application ID name")
+    private boolean sortByName = false;
+
 
     @Override
     protected void execute() {
         ApplicationService service = get(ApplicationService.class);
         List<Application> apps = newArrayList(service.getApplications());
-        Collections.sort(apps, Comparators.APP_COMPARATOR);
+        if (sortByName) {
+            apps.sort(Comparator.comparing(app -> app.id().name()));
+        } else {
+            Collections.sort(apps, Comparators.APP_COMPARATOR);
+        }
 
         if (outputJson()) {
             print("%s", json(service, apps));