Added a more intuitive app management CLI; deprecated the old one for now.

Change-Id: I4f884cbf442b21c08415fe3ca3228edbbb5893f7
diff --git a/cli/src/main/java/org/onosproject/cli/app/ApplicationActivateCommand.java b/cli/src/main/java/org/onosproject/cli/app/ApplicationActivateCommand.java
index 672b6fc..eadaa7d 100644
--- a/cli/src/main/java/org/onosproject/cli/app/ApplicationActivateCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/app/ApplicationActivateCommand.java
@@ -24,6 +24,7 @@
 /**
  * Activates an installed application.
  */
+@Deprecated
 @Command(scope = "onos", name = "app-activate",
         description = "Activates an installed application")
 public class ApplicationActivateCommand extends AbstractShellCommand {
diff --git a/cli/src/main/java/org/onosproject/cli/app/ApplicationCommand.java b/cli/src/main/java/org/onosproject/cli/app/ApplicationCommand.java
new file mode 100644
index 0000000..862e27e
--- /dev/null
+++ b/cli/src/main/java/org/onosproject/cli/app/ApplicationCommand.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.cli.app;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.app.ApplicationAdminService;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.core.ApplicationId;
+
+/**
+ * Manages application inventory.
+ */
+@Command(scope = "onos", name = "app",
+        description = "Manages application inventory")
+public class ApplicationCommand extends AbstractShellCommand {
+
+    static final String INSTALL = "install";
+    static final String UNINSTALL = "uninstall";
+    static final String ACTIVATE = "activate";
+    static final String DEACTIVATE = "deactivate";
+
+    @Argument(index = 0, name = "command",
+            description = "Command name (activate|deactivate|uninstall)",
+            required = true, multiValued = false)
+    String command = null;
+
+    @Argument(index = 1, name = "name", description = "Application name",
+            required = true, multiValued = false)
+    String name = null;
+
+    @Override
+    protected void execute() {
+        ApplicationAdminService service = get(ApplicationAdminService.class);
+        if (command.equals(INSTALL)) {
+            print("Not supported via CLI yet.");
+
+        } else {
+            ApplicationId appId = service.getId(name);
+            if (appId == null) {
+                print("No such application: %s", name);
+                return;
+            }
+
+            if (command.equals(UNINSTALL)) {
+                service.uninstall(appId);
+            } else if (command.equals(ACTIVATE)) {
+                service.activate(appId);
+            } else if (command.equals(DEACTIVATE)) {
+                service.deactivate(appId);
+            }
+        }
+    }
+
+}
diff --git a/cli/src/main/java/org/onosproject/cli/app/ApplicationCommandCompleter.java b/cli/src/main/java/org/onosproject/cli/app/ApplicationCommandCompleter.java
new file mode 100644
index 0000000..b9ea774
--- /dev/null
+++ b/cli/src/main/java/org/onosproject/cli/app/ApplicationCommandCompleter.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.cli.app;
+
+import org.apache.karaf.shell.console.Completer;
+import org.apache.karaf.shell.console.completer.StringsCompleter;
+
+import java.util.List;
+import java.util.SortedSet;
+
+import static org.onosproject.cli.app.ApplicationCommand.*;
+
+/**
+ * Application name completer.
+ */
+public class ApplicationCommandCompleter implements Completer {
+    @Override
+    public int complete(String buffer, int cursor, List<String> candidates) {
+        // Delegate string completer
+        StringsCompleter delegate = new StringsCompleter();
+        SortedSet<String> strings = delegate.getStrings();
+        strings.add(INSTALL);
+        strings.add(UNINSTALL);
+        strings.add(ACTIVATE);
+        strings.add(DEACTIVATE);
+
+        // Now let the completer do the work for figuring out what to offer.
+        return delegate.complete(buffer, cursor, candidates);
+    }
+
+}
diff --git a/cli/src/main/java/org/onosproject/cli/app/ApplicationDeactivateCommand.java b/cli/src/main/java/org/onosproject/cli/app/ApplicationDeactivateCommand.java
index 317e93f..3e0195d 100644
--- a/cli/src/main/java/org/onosproject/cli/app/ApplicationDeactivateCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/app/ApplicationDeactivateCommand.java
@@ -24,6 +24,7 @@
 /**
  * Deactivates an installed application.
  */
+@Deprecated
 @Command(scope = "onos", name = "app-deactivate",
         description = "Deactivates an installed application")
 public class ApplicationDeactivateCommand extends AbstractShellCommand {
diff --git a/cli/src/main/java/org/onosproject/cli/app/ApplicationUninstallCommand.java b/cli/src/main/java/org/onosproject/cli/app/ApplicationUninstallCommand.java
index fd86c74..2e05c0c 100644
--- a/cli/src/main/java/org/onosproject/cli/app/ApplicationUninstallCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/app/ApplicationUninstallCommand.java
@@ -24,6 +24,7 @@
 /**
  * Uninstalls an application.
  */
+@Deprecated
 @Command(scope = "onos", name = "app-uninstall",
         description = "Uninstalls an application")
 public class ApplicationUninstallCommand extends AbstractShellCommand {
diff --git a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index fdfa54c..285de68 100644
--- a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -25,6 +25,16 @@
         </command>
 
         <command>
+            <action class="org.onosproject.cli.app.ApplicationCommand"/>
+            <completers>
+                <ref component-id="appCommandCompleter"/>
+                <ref component-id="appNameCompleter"/>
+                <null/>
+            </completers>
+        </command>
+
+        <!--
+        <command>
             <action class="org.onosproject.cli.app.ApplicationActivateCommand"/>
             <completers>
                 <ref component-id="appNameCompleter"/>
@@ -47,6 +57,7 @@
                 <null/>
             </completers>
         </command>
+        -->
 
         <command>
             <action class="org.onosproject.cli.MetricsListCommand"/>
@@ -55,14 +66,14 @@
         <command>
             <action class="org.onosproject.cli.NodesListCommand"/>
         </command>
-<!--
+        <!--
         <command>
             <action class="org.onosproject.cli.NodeAddCommand"/>
         </command>
         <command>
             <action class="org.onosproject.cli.NodeRemoveCommand"/>
         </command>
--->
+        -->
 
         <command>
             <action class="org.onosproject.cli.RolesCommand"/>
@@ -130,7 +141,7 @@
         <command>
             <action class="org.onosproject.cli.net.IntentRemoveCommand"/>
             <completers>
-                <ref component-id="appIdNameCompleter" />
+                <ref component-id="appIdNameCompleter"/>
                 <ref component-id="intentIdCompleter"/>
                 <null/>
             </completers>
@@ -165,9 +176,9 @@
         </command>
         <command>
             <action class="org.onosproject.cli.net.GetStatistics"/>
-                <completers>
-                    <ref component-id="connectPointCompleter"/>
-                </completers>
+            <completers>
+                <ref component-id="connectPointCompleter"/>
+            </completers>
         </command>
         <command>
             <action class="org.onosproject.cli.net.AddMultiPointToSinglePointIntentCommand"/>
@@ -272,13 +283,14 @@
             <action class="org.onosproject.cli.net.WipeOutCommand"/>
         </command>
         <command>
-			<action class="org.onosproject.cli.net.AddMplsIntent" />
-			<completers>
-			<ref component-id="connectPointCompleter" />
-		</completers>
-		</command>
+            <action class="org.onosproject.cli.net.AddMplsIntent"/>
+            <completers>
+                <ref component-id="connectPointCompleter"/>
+            </completers>
+        </command>
     </command-bundle>
 
+    <bean id="appCommandCompleter" class="org.onosproject.cli.app.ApplicationCommandCompleter"/>
     <bean id="appNameCompleter" class="org.onosproject.cli.app.ApplicationNameCompleter"/>
     <bean id="appIdNameCompleter" class="org.onosproject.cli.app.ApplicationIdNameCompleter"/>
     <bean id="nodeIdCompleter" class="org.onosproject.cli.NodeIdCompleter"/>