Updates to push-intent and leaders command.

Change-Id: Id3fd7932002bf90f79a89f796ce44bab8ea74aab
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/IntentPushTestCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/IntentPushTestCommand.java
index 9326221..32ea13f 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/IntentPushTestCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/IntentPushTestCommand.java
@@ -19,6 +19,7 @@
 import com.google.common.collect.Lists;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
 import org.onlab.onos.cli.AbstractShellCommand;
 import org.onlab.onos.core.ApplicationId;
 import org.onlab.onos.core.CoreService;
@@ -75,16 +76,30 @@
             required = false, multiValued = false)
     String appIds = null;
 
+    @Argument(index = 4, name = "appIdBase",
+            description = "Base Value for Application IDs",
+            required = false, multiValued = false)
+    String appIdBaseStr = null;
+
+    @Option(name = "-i", aliases = "--install",
+            description = "Install intents",
+            required = false, multiValued = false)
+    private boolean installOnly = false;
+
+    @Option(name = "-w", aliases = "--withdraw",
+            description = "Withdraw intents",
+            required = false, multiValued = false)
+    private boolean withdrawOnly = false;
 
     private IntentService service;
     private CountDownLatch latch;
     private long start, end;
     private int apps;
     private int intentsPerApp;
+    private int appIdBase;
     private int count;
     private boolean add;
 
-
     @Override
     protected void execute() {
         service = get(IntentService.class);
@@ -100,21 +115,30 @@
 
         apps = appIds != null ? Integer.parseInt(appIds) : 1;
         intentsPerApp = Integer.parseInt(intentsPerAppId);
+        appIdBase = appIdBaseStr != null ? Integer.parseInt(appIdBaseStr) : 1;
 
         count = intentsPerApp * apps;
 
-
         service.addListener(this);
 
         ArrayListMultimap<Integer, Intent> operations = generateIntents(ingress, egress);
 
-        add = true;
-        latch = new CountDownLatch(count);
-        submitIntents(operations);
+        boolean both = !(installOnly ^ withdrawOnly);
 
-        add = false;
-        latch = new CountDownLatch(count);
-        submitIntents(operations);
+        if (installOnly || both) {
+            add = true;
+            latch = new CountDownLatch(count);
+            submitIntents(operations);
+        }
+
+        if (withdrawOnly || both) {
+            if (withdrawOnly && !both) {
+                print("This should fail for now...");
+            }
+            add = false;
+            latch = new CountDownLatch(count);
+            submitIntents(operations);
+        }
 
         service.removeListener(this);
     }
@@ -125,12 +149,12 @@
         TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
 
         ArrayListMultimap<Integer, Intent> intents = ArrayListMultimap.create();
-        for (int app = 1; app <= apps; app++) {
+        for (int app = 0; app < apps; app++) {
             for (int i = 1; i <= intentsPerApp; i++) {
                 TrafficSelector s = selector
                         .matchEthSrc(MacAddress.valueOf(i))
                         .build();
-                intents.put(app, new PointToPointIntent(appId(), s, treatment,
+                intents.put(app, new PointToPointIntent(appId(app), s, treatment,
                                                         ingress, egress));
 
             }
@@ -178,7 +202,8 @@
      * @return command-line application identifier
      */
     protected ApplicationId appId(Integer id) {
-        return get(CoreService.class).registerApplication("org.onlab.onos.cli-" + id);
+        return get(CoreService.class).registerApplication("org.onlab.onos.cli-"
+                                                                  + (id + appIdBase));
     }
 
     /**
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/LeaderCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/LeaderCommand.java
index cd5ee09..7ea3ebb 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/LeaderCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/LeaderCommand.java
@@ -29,13 +29,15 @@
         description = "Finds the leader for particular topic.")
 public class LeaderCommand extends AbstractShellCommand {
 
+    private static final String FMT = "%-20s: %15s";
+
     @Override
     protected void execute() {
         LeadershipService leaderService = get(LeadershipService.class);
         Map<String, Leadership> leaderBoard = leaderService.getLeaderBoard();
-        print("Topic:\t\tLeader");
+        print(FMT, "Topic", "Leader");
         for (String topic : leaderBoard.keySet()) {
-            print("%s:\t%s", topic, leaderBoard.get(topic).leader().id());
+            print(FMT, topic, leaderBoard.get(topic).leader().id());
         }
     }