Brian O'Connor

Removing duplicate apps from ApplicationNameCompleter

Change-Id: Ib0a79a9971b017afeddf7f3c85b8a1970a072449
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.cli.app; 16 package org.onosproject.cli.app;
17 17
18 +import com.google.common.collect.Sets;
18 import org.apache.karaf.shell.console.completer.ArgumentCompleter; 19 import org.apache.karaf.shell.console.completer.ArgumentCompleter;
19 import org.apache.karaf.shell.console.completer.StringsCompleter; 20 import org.apache.karaf.shell.console.completer.StringsCompleter;
20 import org.onosproject.app.ApplicationService; 21 import org.onosproject.app.ApplicationService;
...@@ -22,8 +23,11 @@ import org.onosproject.app.ApplicationState; ...@@ -22,8 +23,11 @@ import org.onosproject.app.ApplicationState;
22 import org.onosproject.cli.AbstractCompleter; 23 import org.onosproject.cli.AbstractCompleter;
23 import org.onosproject.core.Application; 24 import org.onosproject.core.Application;
24 25
26 +import java.util.Arrays;
27 +import java.util.Collections;
25 import java.util.Iterator; 28 import java.util.Iterator;
26 import java.util.List; 29 import java.util.List;
30 +import java.util.Set;
27 import java.util.SortedSet; 31 import java.util.SortedSet;
28 32
29 import static org.onosproject.app.ApplicationState.ACTIVE; 33 import static org.onosproject.app.ApplicationState.ACTIVE;
...@@ -43,6 +47,15 @@ public class ApplicationNameCompleter extends AbstractCompleter { ...@@ -43,6 +47,15 @@ public class ApplicationNameCompleter extends AbstractCompleter {
43 ArgumentCompleter.ArgumentList list = getArgumentList(); 47 ArgumentCompleter.ArgumentList list = getArgumentList();
44 String cmd = list.getArguments()[1]; 48 String cmd = list.getArguments()[1];
45 49
50 + // Grab apps already on the command (to prevent tab-completed duplicates)
51 + final Set previousApps;
52 + if (list.getArguments().length > 2) {
53 + previousApps = Sets.newHashSet(
54 + Arrays.copyOfRange(list.getArguments(), 2, list.getArguments().length));
55 + } else {
56 + previousApps = Collections.emptySet();
57 + }
58 +
46 // Fetch our service and feed it's offerings to the string completer 59 // Fetch our service and feed it's offerings to the string completer
47 ApplicationService service = get(ApplicationService.class); 60 ApplicationService service = get(ApplicationService.class);
48 Iterator<Application> it = service.getApplications().iterator(); 61 Iterator<Application> it = service.getApplications().iterator();
...@@ -50,6 +63,9 @@ public class ApplicationNameCompleter extends AbstractCompleter { ...@@ -50,6 +63,9 @@ public class ApplicationNameCompleter extends AbstractCompleter {
50 while (it.hasNext()) { 63 while (it.hasNext()) {
51 Application app = it.next(); 64 Application app = it.next();
52 ApplicationState state = service.getState(app.id()); 65 ApplicationState state = service.getState(app.id());
66 + if (previousApps.contains(app.id().name())) {
67 + continue;
68 + }
53 if (cmd.equals("uninstall") || 69 if (cmd.equals("uninstall") ||
54 (cmd.equals("activate") && state == INSTALLED) || 70 (cmd.equals("activate") && state == INSTALLED) ||
55 (cmd.equals("deactivate") && state == ACTIVE)) { 71 (cmd.equals("deactivate") && state == ACTIVE)) {
......